package com.css.fxfzfxqh.modules.reportmanagement.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzfxqh.base.attachment.entity.AttachmentInfoEntity;
import com.css.fxfzfxqh.base.attachment.service.AttachmentInfoService;
import com.css.fxfzfxqh.common.rest.JcsjRestManager;
import com.css.fxfzfxqh.common.rest.model.bo.GetGDPBo;
import com.css.fxfzfxqh.common.rest.model.bo.JcPopulationGridBo;
import com.css.fxfzfxqh.modules.buildingIndividual.param.param;
import com.css.fxfzfxqh.modules.buildings.VO.CurveVo;
import com.css.fxfzfxqh.modules.buildings.definitiveEvaluation.casualtiesDE.entity.PCC;
import com.css.fxfzfxqh.modules.buildings.probabilityEvaluation.publicOperate.service.PublicOperateService;
import com.css.fxfzfxqh.modules.buildings.probabilityEvaluation.publicOperate.vo.BasicLibraryVo;
import com.css.fxfzfxqh.modules.reportTemplate.entity.Template;
import com.css.fxfzfxqh.modules.reportTemplate.repository.TemplateRepository;
import com.css.fxfzfxqh.modules.reportmanagement.entity.ReportCommonData;
import com.css.fxfzfxqh.modules.reportmanagement.reportutil.DzzhDzryqkCustomTableMethodPolicy;
import com.css.fxfzfxqh.modules.reportmanagement.reportutil.DzzhDzryqkCustomTableMethodPolicy2;
import com.css.fxfzfxqh.modules.reportmanagement.reportutil.JzwysxCustomTableMethodPolicy;
import com.css.fxfzfxqh.modules.reportmanagement.service.ExportPGReportDataService;
import com.css.fxfzfxqh.modules.reportmanagement.service.ExportReportDataService;
import com.css.fxfzfxqh.modules.reportmanagement.service.GraphService;
import com.css.fxfzfxqh.modules.reportmanagement.service.PgbgZdryqkReportService;
import com.css.fxfzfxqh.modules.reportmanagement.vo.ReportAnalysis;
import com.css.fxfzfxqh.modules.reportmanagement.vo.ReportYsx;
import com.css.fxfzfxqh.modules.reportmanagement.vo.ReportYsxVO;
import com.css.fxfzfxqh.modules.seismicHazardData.entity.SettingInfluenceFliedEntity;
import com.css.fxfzfxqh.modules.seismicHazardData.repository.SeismicImpactFieldRepository;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.model.entity.FxqhAssessEdQhResult;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.model.entity.FxqhAssessPdQhResult;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.model.vo.FxqhAssessEdQhResultVo;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.model.vo.FxqhAssessPdQhResultVo;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.repository.EnterAssessQhRepository;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.service.EnterAssessQhService;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.service.ProbabilityAssessQhService;
import com.css.fxfzfxqh.modules.singleIndexRiskZoning.vo.GdpVO;
import com.css.fxfzfxqh.modules.synthesis.entity.PopulationAndLoss;
import com.css.fxfzfxqh.modules.synthesis.param.QueryParam;
import com.css.fxfzfxqh.modules.util.repository.PccRepository;
import com.css.fxfzfxqh.util.*;
import com.css.fxfzfxqh.web.PlatformSessionContext;
import com.css.fxfzfxqh.zcpt.sys.entity.SUser;
import com.css.fxfzfxqh.zcpt.sys.service.SUserService;
import com.css.fxfzfxqh.zcpt.sys.service.SysAreaService;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.data.*;
import com.deepoove.poi.data.style.CellStyle;
import com.deepoove.poi.data.style.ParagraphStyle;
import com.deepoove.poi.data.style.TableStyle;
import com.deepoove.poi.plugin.table.LoopColumnTableRenderPolicy;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.deepoove.poi.policy.RenderPolicy;
import com.deepoove.poi.util.RegexUtils;
import com.deepoove.poi.xwpf.NiceXWPFDocument;
import com.sun.scenario.effect.Merge;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Service
public class ExportReportDataServiceImpl implements ExportReportDataService {
    private static final Logger logger = LoggerFactory.getLogger(ExportReportDataServiceImpl.class);

    @Value("${image.localDir}")
    private String localDir;
    @Value("${image.ctLocalDir}")
    private String ctLocalDir;
    @Autowired
    private AttachmentInfoService attachmentInfoService;
    @Autowired
    PgbgZdryqkReportService pgbgZdryqkReportService;
    @Autowired
    ExportPGReportDataService exportPGReportDataService;
    @Autowired
    ExportReportDataService exportReportDataService;
    @Resource
    TemplateRepository templateRepository;
    @Autowired
    JcsjRestManager jcsjRestManager;
    @Autowired
    FImCountUtils fImCountUtils;
    @Autowired
    private EnterAssessQhService enterAssessQhService;
    @Autowired
    private ProbabilityAssessQhService probabilityAssessQhService;
    @Resource
    SysAreaService sysAreaService;
    @Resource
    SUserService sUserService;
    @Resource
    PublicOperateService publicOperateService;
    @Resource
    private EnterAssessQhRepository enterAssessQhRepository;

    //行循环策略
    LoopRowTableRenderPolicy rowTableRenderPolicy = new LoopRowTableRenderPolicy();

    //列循环策略
    LoopColumnTableRenderPolicy columnTableRenderPolicy = new LoopColumnTableRenderPolicy();

    //建筑物易损性 表格策略
    JzwysxCustomTableMethodPolicy customTableMethodPolicy = new JzwysxCustomTableMethodPolicy();

    //地震人员受伤评估/3.3 地震人员死亡评估 表格策略
    DzzhDzryqkCustomTableMethodPolicy dzzhDzryqkCustomTableMethodPolicy = new DzzhDzryqkCustomTableMethodPolicy();

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private PgbgZdryqkReportService pgldReportService;

    @Resource
    GraphService graphService;

    @Resource
    SeismicImpactFieldRepository seismicImpactFieldRepository;

    @Resource
    PccRepository pccRepository;

    //根据任务ID查询任务对象
    @Override
    public Map<String,Object> getTaskObjById(String taskId){
        Map<String,Object> map = new HashMap<>();
        try{
            String sql ="select * from fxqh_calculation_tasks where id='%s'";
            sql =String.format(sql,taskId);
            logger.info("getTaskObjById:{}",sql);
            map = jdbcTemplate.queryForMap(sql);
        } catch (EmptyResultDataAccessException e) {
            e.printStackTrace();
        }
        return map;
    }
    //查询1、	建筑物单体数据
    @Override
    public List<ReportCommonData> getBuildingIndividualCal(String taskId){
        StringBuilder sb = new StringBuilder();
        sb.append("select area as data_Value ,                                                                                               ");
        sb.append("case when t3.dict_item_name is not null then concat(t2.dict_item_name,'-',t3.dict_item_name)                              ");
        sb.append("			else t2.dict_item_name end as data_Name                                                           ");
        sb.append("from (                                                                                                                    ");
        sb.append("select sum(CAST(area as DECIMAL(10,2))) as area,structure_type1,structure_type2 from fxqh_building_individual_copy      ");
        sb.append("where task_id='%s'                                                                          ");
        sb.append("group by structure_type1,structure_type2                                                                                  ");
        sb.append(")  T1                                                                                                                     ");
        sb.append("                                                                                                                          ");
        sb.append("left   join                                                                                                               ");
        sb.append("(                                                                                                                         ");
        sb.append("                                                                                                                          ");
        sb.append("select di.dict_item_code,di.dict_item_name from sys_dict_item di,sys_dict d                                               ");
        sb.append("where d.dict_id = di.dict_id and d.is_valid = '1'                                                                         ");
        sb.append("and di.is_valid = '1' and d.dict_code in ('jglxyj','qtjgej','gycfej','gjhntjgej')                                         ");
        sb.append("order by d.dict_id,di.sort                                                                                                ");
        sb.append("                                                                                                                          ");
        sb.append(")  t2 on t1.structure_type1=t2.dict_item_code                                                                             ");
        sb.append("                                                                                                                          ");
        sb.append("left join                                                                                                                 ");
        sb.append("(                                                                                                                         ");
        sb.append("                                                                                                                          ");
        sb.append("select di.dict_item_code,di.dict_item_name from sys_dict_item di,sys_dict d                                               ");
        sb.append("where d.dict_id = di.dict_id and d.is_valid = '1'                                                                         ");
        sb.append("and di.is_valid = '1' and d.dict_code in ('jglxyj','qtjgej','gycfej','gjhntjgej')                                         ");
        sb.append("order by d.dict_id,di.sort                                                                                                ");
        sb.append("                                                                                                                          ");
        sb.append(")  t3 on t1.structure_type2=t3.dict_item_code  order by data_value desc                                                                              ");
        String sql=String.format(sb.toString(),taskId);
        logger.info("执行getBuildingIndividualCal方法查询的SQL:{}",sql);
        List<ReportCommonData> dataList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReportCommonData.class));

        return dataList;
    }

    //建筑物单体数据 2)	各个设防情况下的建筑面积
    @Override
    public List<ReportCommonData> getBuildingIndividualSfqkCal(String taskId){
        StringBuilder sb = new StringBuilder();
        sb.append("select area as data_Value ,defence_level,t2.dict_item_name,                                                   ");
        sb.append("t2.dict_item_name as data_Name                                                                                ");
        sb.append("from (                                                                                                       ");
        sb.append("select sum(CAST(area as DECIMAL(10,2))) as area,defence_level from fxqh_building_individual_copy           ");
        sb.append("where task_id='%s'                                                             ");
        sb.append("group by defence_level                                                                                       ");
        sb.append(")  T1                                                                                                        ");
        sb.append("                                                                                                             ");
        sb.append("inner   join                                                                                                 ");
        sb.append("(                                                                                                            ");
        sb.append("                                                                                                             ");
        sb.append("select di.dict_item_code,di.dict_item_name from sys_dict_item di,sys_dict d                                  ");
        sb.append("where d.dict_id = di.dict_id and d.is_valid = '1'                                                            ");
        sb.append("and di.is_valid = '1' and d.dict_code in ('sfqk')                                                            ");
        sb.append("order by d.dict_id,di.sort                                                                                   ");
        sb.append("                                                                                                             ");
        sb.append(")  t2 on t1.defence_level=t2.dict_item_code  order by data_value desc                                                                 ");
        String sql = String.format(sb.toString(),taskId);
        logger.info("getBuildingIndividualSfqkCal方法查询的SQL:{}",sql);
        List<ReportCommonData> dataList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReportCommonData.class));
        return dataList;
    }

    //查询建筑物格网数据   结构类型的建筑面积
    @Override
    public List<ReportCommonData> getGridDataCal(String taskId){
        StringBuilder sb = new StringBuilder();
        sb.append("select area as dataValue ,structure_type,t2.dict_item_name, dictionary,       ");
        sb.append("t2.dict_item_name as dataName                                                       ");
        sb.append("from (                                                                              ");
        sb.append("select sum(total_area) as area,structure_type ,dictionary from fxqh_grid_data_copy              ");
        sb.append("where task_id='%s'                                                                   ");
        sb.append("group by structure_type, dictionary                                           ");
        sb.append(")  T1                                                                               ");
        sb.append("                                                                                    ");
        sb.append("inner   join                                                                        ");
        sb.append("(                                                                                   ");
        sb.append("                                                                                    ");
        sb.append("select di.dict_item_code,di.dict_item_name from sys_dict_item di,sys_dict d         ");
        sb.append("where d.dict_id = di.dict_id and d.is_valid = '1'                                   ");
        sb.append("and di.is_valid = '1' and d.dict_code in ('jzwglgwlx')                              ");
        sb.append("order by d.dict_id,di.sort                                                          ");
        sb.append("                                                                                    ");
        sb.append(")  t2 on t1.dictionary=t2.dict_item_code order by dataValue desc                                 ");
        String sql = String.format(sb.toString(),taskId);
        logger.info("getGridDataCal方法查询的SQL:{}",sql);
        List<ReportCommonData> dataList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReportCommonData.class));
        return dataList;
    }

    //查询 建筑物格网数据  各个设防情况下的建筑面积
    @Override
    public List<ReportCommonData> getGridDataSfqkCal(String taskId){
        StringBuilder sb = new StringBuilder();
        sb.append("select                                                                                          ");
        sb.append("unnest(string_to_array((                                                                        ");
        sb.append("COALESCE(sf_0,'0')||','||                                                                       ");
        sb.append("COALESCE(sf_6,'0')||','||                                                                       ");
        sb.append("COALESCE(sf_7,'0')||','||                                                                       ");
        sb.append("COALESCE(sf_8,'0')||','||                                                                       ");
        sb.append("COALESCE(sf_9,'0')) ,',')) data_value,                                                          ");
        sb.append("                                                                                                ");
        sb.append("unnest(string_to_array('未设防,6度,7度,8度,9度',',')) data_name                                 ");
        sb.append("from (                                                                                          ");
        sb.append("	select task_id,sf_0,sf_6,sf_7,sf_8,sf_9 from (                                          ");
        sb.append("	select task_id, CAST(sum( total_area * sf_intensity/100)  as DECIMAL(18,2)) as sf_0,    ");
        sb.append("	 CAST(sum(total_area * sf_intensity6/100) as DECIMAL(18,2)) as sf_6,                    ");
        sb.append("	 CAST(sum(total_area * sf_intensity7/100) as DECIMAL(18,2))as sf_7,                     ");
        sb.append("	 CAST(sum(total_area * sf_intensity8/100) as DECIMAL(18,2)) as sf_8,                   ");
        sb.append("	 CAST(sum(total_area * sf_intensity9/100) as DECIMAL(18,2)) as sf_9                     ");
        sb.append("	from fxqh_grid_data_copy                                                                ");
        //sb.append("	from fxqh_grid_data_copy_data1                                                          ");
        sb.append("	where task_id='%s'                                        ");
        sb.append("	group by task_id                                                                        ");
        sb.append("	) a                                                                                     ");
        sb.append(") b order by data_name asc                                                                                           ");
        String sql = String.format(sb.toString(),taskId);
        logger.info("getGridDataSfqkCal方法查询的SQL:{}",sql);
        List<ReportCommonData> dataList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReportCommonData.class));
        return dataList;
    }

    //查询建筑物重置单价数据
    @Override
    public List<Map<String,Object>> getFxqhBuildingPriceTask(String taskId){
        StringBuilder sb  =new StringBuilder(" select * from  fxqh_building_price_task where task_id='%s'  and del_flag='0' ");
        String sql = String.format(sb.toString(),taskId);
        logger.info("getFxqhBuildingPriceTask方法查询的SQL:{}",sql);
        List<Map<String,Object>> dataList =  jdbcTemplate.queryForList(sql);
        return dataList;
    }

    public List<Map<String,Object>> getFxqhBuildingPriceTask(PCC pcc){
        String sql=" select * from  fxqh_building_reset_unit_price where  del_flag='0' and province='"+pcc.getPpName()+"' and city='"+pcc.getCityName()+"' and county='"+pcc.getName()+"'";
        logger.info("getFxqhBuildingPriceTask方法查询的SQL:{}",sql);
        List<Map<String,Object>> dataList =  jdbcTemplate.queryForList(sql);
        return dataList;
    }


    @Override
    public  Map<String, String> createWordReport(Map<String,RenderPolicy> policyMap, Map<String, Object> paramMap, String modelName, String attachPath, String fileDirId) {
        // 文件存放根目录
        String rootPath ="D:\\csse\\";
//        String rootPath = "D:" + File.separator+"report"+ File.separator;
//        String rootPath = localDir;
        File dir = new File(rootPath);

        if (!dir.exists()) {
            dir.mkdir();
        }
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String nowStr = sdf.format(now);
        //String desFileName = "地震灾害损失预评估和应急处置要点报告（详本）报告" +nowStr+ ".docx";
        String desFileName=modelName+nowStr+".docx";
        String docxPath =  rootPath +File.separator+ desFileName;
        // 根据模板渲染word、并且生成pdf文件 fileDirId + attachPath fileDirId + attachPath
        //ClassPathResource classPathResource = new ClassPathResource("static/地震灾害损失预评估和应急处置要点报告.docx");
        try (
                InputStream inputStream = new FileInputStream( fileDirId + attachPath)) {
            //InputStream inputStream = new FileInputStream("D:\\公司文档数据\\预评估\\报告模板\\地震灾害损失预评估和应急处置要点报告-详本-20231013(1).docx" ))  {
            //渲染表格  动态行
            //LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
            //HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();

            ConfigureBuilder builder = Configure.builder()
                    .useSpringEL()  //使用SpringEL表达式
                    .buildGrammerRegex(RegexUtils.createGeneral("{{", "}}"));//允许除了标签前后缀外的任意字符

            Set<String> listKeySet = policyMap.keySet();
            for (String key:listKeySet) {
                builder= builder.bind(key,policyMap.get(key));
            }
            Configure config = builder.build();
            // 通过协查函模板，开始生成电子协查函
            try (
                    XWPFTemplate template = XWPFTemplate.compile(inputStream,config).render(paramMap);
                    OutputStream outDocx = Files.newOutputStream(Paths.get(docxPath))) {

                ZipSecureFile.setMinInflateRatio(-1D);
                // 输出word
                template.getXWPFDocument().write(outDocx);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, String> map = new HashMap<>(4);
        map.put("rootPath", rootPath);
        map.put("docxName", desFileName);
        return map;
    }


    //01确定评估-设定烈度
    @Override
    public Map<String, String> generateWordReportData(String taskId, String bgId) throws Exception{
        Map<String, Object> paramMap = new HashMap<>();
        Map<String,String> resultMap = new HashMap<>();
        Map<String,RenderPolicy> policyMap = new HashMap<>();
        Map<String,Object> taskObj = getTaskObjById(taskId);
        String inputNum="1000000101";
        this.buildCommonReportParam(paramMap,policyMap,taskId,taskObj,inputNum,"1");
        //4.1结构破坏评估-4.1.2建筑物破坏状态评估结果
        List<Map<String, Object>> buildinDamageList=exportPGReportDataService.getbuildinDamage1(taskId,"0");

        Map<Object, List<Map<String, Object>>> conditionMap = buildinDamageList.stream().collect(Collectors.groupingBy(map -> map.get("condition")));
        List<Map<String, Object>> damageList  = new ArrayList<>();
        conditionMap.forEach((k,v)->{
            //k是烈度
            Map<String,Object> map = new HashMap<>();
            map.put("province_name",v.get(0).get("province_name"));
            map.put("city_name",v.get(0).get("city_name"));
            map.put("county_name",v.get(0).get("county_name"));
            Integer sort = 0;
            switch (String.valueOf(v.get(0).get("intensity"))){
                //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
                case "ld1": map.put("intensity","Ⅵ"); sort = 1;break;
                case "ld2": map.put("intensity","Ⅶ"); sort = 2; break;
                case "ld3": map.put("intensity","Ⅷ"); sort = 3;break;
                case "ld4": map.put("intensity","Ⅸ"); sort = 4;break;
                case "ld5": map.put("intensity","Ⅹ"); sort = 5;break;
            }
            map.put("pgcd1",new BigDecimal(v.get(0).get("calculated_value").toString()).compareTo(BigDecimal.ZERO)==0?"0":new BigDecimal(v.get(0).get("calculated_value").toString()).setScale(2,RoundingMode.HALF_DOWN));
            map.put("pgcd2",new BigDecimal(v.get(1).get("calculated_value").toString()).compareTo(BigDecimal.ZERO)==0?"0":new BigDecimal(v.get(1).get("calculated_value").toString()).setScale(2,RoundingMode.HALF_DOWN));
            map.put("pgcd3",new BigDecimal(v.get(2).get("calculated_value").toString()).compareTo(BigDecimal.ZERO)==0?"0":new BigDecimal(v.get(2).get("calculated_value").toString()).setScale(2,RoundingMode.HALF_DOWN));
            map.put("pgcd4",new BigDecimal(v.get(3).get("calculated_value").toString()).compareTo(BigDecimal.ZERO)==0?"0":new BigDecimal(v.get(3).get("calculated_value").toString()).setScale(2,RoundingMode.HALF_DOWN));
            map.put("pgcd5",new BigDecimal(v.get(4).get("calculated_value").toString()).compareTo(BigDecimal.ZERO)==0?"0":new BigDecimal(v.get(4).get("calculated_value").toString()).setScale(2,RoundingMode.HALF_DOWN));
            map.put("sort",sort);
            damageList.add(map);
        });
//        List<Map<String, Object>> buildinDamageList=exportPGReportDataService.getbuildinDamage(taskId,"0");
//        for (Map<String, Object> stringObjectMap : buildinDamageList) {
//            switch (String.valueOf(stringObjectMap.get("intensity"))){
//                //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
//                case "ld1": stringObjectMap.put("intensity","Ⅵ");break;
//                case "ld2": stringObjectMap.put("intensity","Ⅶ");break;
//                case "ld3": stringObjectMap.put("intensity","Ⅷ");break;
//                case "ld4": stringObjectMap.put("intensity","Ⅸ");break;
//                case "ld5": stringObjectMap.put("intensity","Ⅹ");break;
//            }
//        }
        Collections.sort(damageList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                // 根据"key"的值进行比较，假设它们都存在且为Integer类型
                return Integer.compare((Integer) o1.get("sort"), (Integer) o2.get("sort"));
            }
        });
        policyMap.put("buildinDamageList",rowTableRenderPolicy);
//        paramMap.put("buildinDamageList",buildinDamageList);
        paramMap.put("buildinDamageList",damageList);
        //4.4地震直接经济损失评估-4.4.2经济损失评估结果-1、按VI~X烈度下经济损失统计
        Object assess_obj = taskObj.get("assess_obj");
        if(assess_obj!=null&&assess_obj.toString().contains("2")) {//经济
            List<Map<String, Object>> economicLossList = exportPGReportDataService.getEconomicLoss(taskId,"11");
            policyMap.put("economicLossList", rowTableRenderPolicy);
            paramMap.put("economicLossList", economicLossList);
        }
        createWordReport1(policyMap, paramMap, inputNum,bgId);
        logger.info("word报告生产成功");

        return resultMap;
    }

    private void countMap(List<FxqhAssessEdQhResultVo> jgAssessEdQhList,int count1,int count2,int count3,int count4,int count5,Map<String, Integer> paramMap,String mapKey){
        for (FxqhAssessEdQhResultVo fxqhAssessEdQhResultVo : jgAssessEdQhList) {
//            switch (fxqhAssessEdQhResultVo.getQhLevel()){
//                case "I":   result = result.add(BigDecimal.ONE);;break;
//                case "II":  result = result.add(BigDecimal.ONE);;break;
//                case "III": result = result.add(BigDecimal.ONE);;break;
//                case "IV":  result = result.add(BigDecimal.ONE);;break;
//                case "V":   result = result.add(BigDecimal.ONE);;break;
//                default:break;
//            }
            switch (fxqhAssessEdQhResultVo.getQhLevel()){

                case "I":  count1++;break;
                case "II":  count2++;break;
                case "III":  count3++;break;
                case "IV":  count4++;break;
                case "V":  count5++;break;
                default:break;
            }
        }
        paramMap.put(mapKey+"count1",count1);
        paramMap.put(mapKey+"count2",count2);
        paramMap.put(mapKey+"count3",count3);
        paramMap.put(mapKey+"count4",count4);
        paramMap.put(mapKey+"count5",count5);
        count1 = count2 =count3 =count4 = count5 = 0;
    }

    private void countMap3(List<FxqhAssessPdQhResultVo> jgAssessEdQhList,int count1,int count2,int count3,int count4,int count5,Map<String, Integer> paramMap,String mapKey){
        for (FxqhAssessPdQhResultVo fxqhAssessEdQhResultVo : jgAssessEdQhList) {
//            switch (fxqhAssessEdQhResultVo.getQhLevel()){
//                case "I":   result = result.add(BigDecimal.ONE);;break;
//                case "II":  result = result.add(BigDecimal.ONE);;break;
//                case "III": result = result.add(BigDecimal.ONE);;break;
//                case "IV":  result = result.add(BigDecimal.ONE);;break;
//                case "V":   result = result.add(BigDecimal.ONE);;break;
//                default:break;
//            }
            switch (fxqhAssessEdQhResultVo.getQhLevel()){

                case "I":  count1++;break;
                case "II":  count2++;break;
                case "III":  count3++;break;
                case "IV":  count4++;break;
                case "V":  count5++;break;
                default:break;
            }
        }
        paramMap.put(mapKey+"count1",count1);
        paramMap.put(mapKey+"count2",count2);
        paramMap.put(mapKey+"count3",count3);
        paramMap.put(mapKey+"count4",count4);
        paramMap.put(mapKey+"count5",count5);
        count1 = count2 =count3 =count4 = count5 = 0;
    }

    private void insertList(List<FxqhAssessEdQhResultVo> srcAssessEdQhList,List<FxqhAssessEdQhResultVo> deskAssessEdQhList1,List<FxqhAssessEdQhResultVo> deskAssessEdQhList2,
                            List<FxqhAssessEdQhResultVo> deskAssessEdQhList3,List<FxqhAssessEdQhResultVo>
                                    deskAssessEdQhList4,List<FxqhAssessEdQhResultVo> deskAssessEdQhList5,String type){
        if("1".equals(type)){
            for (FxqhAssessEdQhResultVo fxqhAssessEdQhResultVo : srcAssessEdQhList) {
                switch (fxqhAssessEdQhResultVo.getCondition()){
                    case "VI":  deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);break;
                    case "VII":  deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);break;
                    case "VIII":  deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);break;
                    case "IX":  deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);break;
                    case "X":  deskAssessEdQhList5.add(fxqhAssessEdQhResultVo);break;
                    default:break;
                }
            }
        }else if("2".equals(type)){
            for (FxqhAssessEdQhResultVo fxqhAssessEdQhResultVo : srcAssessEdQhList) {
                switch (fxqhAssessEdQhResultVo.getCondition()){
                    case "50年内超越概率63%":  deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);break;
                    case "50年内超越概率10%":  deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);break;
                    case "50年内超越概率2%":  deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);break;
                    case "100年内超越概率1%":  deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);break;
                    default:break;
                }
            }
        }else if("3".equals(type)){
            for (FxqhAssessEdQhResultVo fxqhAssessEdQhResultVo : srcAssessEdQhList) {
                deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);
            }
        }

    }
    private void insertList3(List<FxqhAssessPdQhResultVo> srcAssessEdQhList,List<FxqhAssessPdQhResultVo> deskAssessEdQhList1,List<FxqhAssessPdQhResultVo> deskAssessEdQhList2,
                            List<FxqhAssessPdQhResultVo> deskAssessEdQhList3,List<FxqhAssessPdQhResultVo>
                                    deskAssessEdQhList4,List<FxqhAssessPdQhResultVo> deskAssessEdQhList5,String type){
        if("1".equals(type)){
            for (FxqhAssessPdQhResultVo fxqhAssessEdQhResultVo : srcAssessEdQhList) {
                switch (fxqhAssessEdQhResultVo.getCondition()){
                    case "VI":  deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);break;
                    case "VII":  deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);break;
                    case "VIII":  deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);break;
                    case "IX":  deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);break;
                    case "X":  deskAssessEdQhList5.add(fxqhAssessEdQhResultVo);break;
                    default:break;
                }
            }
        }else if("2".equals(type)){
            for (FxqhAssessPdQhResultVo fxqhAssessEdQhResultVo : srcAssessEdQhList) {
                switch (fxqhAssessEdQhResultVo.getCondition()){
                    case "50年内超越概率63%":  deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);break;
                    case "50年内超越概率10%":  deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);break;
                    case "50年内超越概率2%":  deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);break;
                    case "100年内超越概率1%":  deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);break;
                    default:break;
                }
            }
        }else if("3".equals(type)){
            for (FxqhAssessPdQhResultVo fxqhAssessEdQhResultVo : srcAssessEdQhList) {
                deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);
            }
        }

    }

    private void insertList2(List<PopulationAndLoss> srcAssessEdQhList,List<PopulationAndLoss> deskAssessEdQhList1,List<PopulationAndLoss> deskAssessEdQhList2,
                            List<PopulationAndLoss> deskAssessEdQhList3,List<PopulationAndLoss>
                                    deskAssessEdQhList4,List<PopulationAndLoss> deskAssessEdQhList5){
            for (PopulationAndLoss fxqhAssessEdQhResultVo : srcAssessEdQhList) {
                if("0".equals(fxqhAssessEdQhResultVo.getCategory())) {
                    switch (fxqhAssessEdQhResultVo.getType()){
                        case "ld1":  deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);break;
                        case "ld2":  deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);break;
                        case "ld3":  deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);break;
                        case "ld4":  deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);break;
                        case "ld5":  deskAssessEdQhList5.add(fxqhAssessEdQhResultVo);break;
                        default:break;
                    }
                }else if("1".equals(fxqhAssessEdQhResultVo.getCategory())) {
                    switch (fxqhAssessEdQhResultVo.getType()){
                        case "sgglsz1":  deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);break;
                        case "sgglsz2":  deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);break;
                        case "sgglsz3":  deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);break;
                        case "sgglsz4":  deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);break;
                        default:break;
                    }
                }else if("2".equals(fxqhAssessEdQhResultVo.getCategory())) {
                    deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);
                }

            }
    }

    private void countMap2(List<PopulationAndLoss> jgAssessEdQhList,int count1,int count2,int count3,int count4,int count5,Map<String, Integer> paramMap,String mapKey){
        for (PopulationAndLoss fxqhAssessEdQhResultVo : jgAssessEdQhList) {
            switch (fxqhAssessEdQhResultVo.getLevel()){
                case "Ⅰ":  count1++;break;
                case "Ⅱ":  count2++;break;
                case "Ⅲ":  count3++;break;
                case "Ⅳ":  count4++;break;
                case "Ⅴ":  count5++;break;
                default:break;
            }
        }
        paramMap.put(mapKey+"count1",count1);
        paramMap.put(mapKey+"count2",count2);
        paramMap.put(mapKey+"count3",count3);
        paramMap.put(mapKey+"count4",count4);
        paramMap.put(mapKey+"count5",count5);
        count1 = count2 =count3 =count4 = count5 = 0;
    }
    private void insertList1(List<FxqhAssessPdQhResultVo> srcAssessEdQhList, List<FxqhAssessPdQhResultVo> deskAssessEdQhList1, List<FxqhAssessPdQhResultVo> deskAssessEdQhList2,
                             List<FxqhAssessPdQhResultVo> deskAssessEdQhList3, List<FxqhAssessPdQhResultVo> deskAssessEdQhList4, List<FxqhAssessPdQhResultVo> deskAssessEdQhList5, String[] yearSplit) {
        for (FxqhAssessPdQhResultVo fxqhAssessEdQhResultVo : srcAssessEdQhList) {
            String condition = fxqhAssessEdQhResultVo.getCondition();
            for (int i = 0; i < yearSplit.length; i++) {
                if (condition.equals( yearSplit[i])) {
                    switch (i) {
                        case 0:
                            deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);
                            break;
                        case 1:
                            deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);
                            break;
                        case 2:
                            deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);
                            break;
                        case 3:
                            deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);
                            break;
                        case 4:
                            deskAssessEdQhList5.add(fxqhAssessEdQhResultVo);
                            break;
                    }
                    break;
                }
            }
        }
    }

    private void insertListzh(List<PopulationAndLoss> srcAssessEdQhList, List<PopulationAndLoss> deskAssessEdQhList1, List<PopulationAndLoss> deskAssessEdQhList2,
                             List<PopulationAndLoss> deskAssessEdQhList3, List<PopulationAndLoss> deskAssessEdQhList4, List<PopulationAndLoss> deskAssessEdQhList5, String[] yearSplit) {
        for (PopulationAndLoss fxqhAssessEdQhResultVo : srcAssessEdQhList) {
            String condition = fxqhAssessEdQhResultVo.getType();
            for (int i = 0; i < yearSplit.length; i++) {
                if (condition == yearSplit[i]) {
                    switch (i) {
                        case 0:
                            deskAssessEdQhList1.add(fxqhAssessEdQhResultVo);
                            break;
                        case 1:
                            deskAssessEdQhList2.add(fxqhAssessEdQhResultVo);
                            break;
                        case 2:
                            deskAssessEdQhList3.add(fxqhAssessEdQhResultVo);
                            break;
                        case 3:
                            deskAssessEdQhList4.add(fxqhAssessEdQhResultVo);
                            break;
                        case 4:
                            deskAssessEdQhList5.add(fxqhAssessEdQhResultVo);
                            break;
                    }
                    break;
                }
            }
        }
    }
    private void countMap1(List<FxqhAssessPdQhResultVo> jgAssessEdQhList,int count1,int count2,int count3,int count4,int count5,Map<String, Object> paramMap,String mapKey){
        for (FxqhAssessPdQhResultVo fxqhAssessEdQhResultVo : jgAssessEdQhList) {
            switch (fxqhAssessEdQhResultVo.getQhLevel()){
                case "I":  count1++;break;
                case "II":  count2++;break;
                case "III":  count3++;break;
                case "IV":  count4++;break;
                case "V":  count5++;break;
                default:break;
            }
        }
        paramMap.put(mapKey+"count1",count1);
        paramMap.put(mapKey+"count2",count2);
        paramMap.put(mapKey+"count3",count3);
        paramMap.put(mapKey+"count4",count4);
        paramMap.put(mapKey+"count5",count5);
        count1 = count2 = count3 = count4 = count5 = 0;
    }

    //02确定评估-四个概率水准
    @Override
    public Map<String, String> conditionWordReportData(String taskId, String bgId) throws Exception{
        Map<String, Object> paramMap = new HashMap<>();
        Map<String,String> resultMap = new HashMap<>();
        Map<String,RenderPolicy> policyMap = new HashMap<>();
        Map<String,Object> taskObj = getTaskObjById(taskId);
        String inputNum="1000000102";
        this.buildCommonReportParam(paramMap,policyMap,taskId,taskObj,inputNum,"2");
        //4.1结构破坏评估-4.1.1建筑物破坏状态评估方法
        List<Map<String, Object>> buildinDamageMethodList=exportPGReportDataService.getbuildinDamageMethod(taskId);
        for (Map<String, Object> stringObjectMap : buildinDamageMethodList) {
            switch (stringObjectMap.get("condition").toString()){
                //4个概率水准时（50年内超越概率63%、50年内超越概率10%、50年内超越概率2%、100年内超越概率1%）
                case "sgglsz1": stringObjectMap.put("condition","50年超越概率63%");break;
                case "sgglsz2": stringObjectMap.put("condition","50年超越概率10%");break;
                case "sgglsz3": stringObjectMap.put("condition","50年超越概率2%");break;
                case "sgglsz4": stringObjectMap.put("condition","100年超越概率1%");break;
            }
        }
        policyMap.put("buildinDamageMethodList",rowTableRenderPolicy);
        paramMap.put("buildinDamageMethodList",buildinDamageMethodList);

        Object ld_pga = taskObj.get("ld_pga");
        String input = "0";
        if(ld_pga!=null&&ld_pga.toString().contains("1")){
            paramMap.put("assess_obj_flag_4", true);
            input = "22";
        }else{
            paramMap.put("assess_obj_flag_3", true);
            input = "21";
        }

        Object assess_obj = taskObj.get("assess_obj");
        if(assess_obj!=null&&assess_obj.toString().contains("2")){//经济
            //4.4.2经济损失评估结果-按行政区划统计分析四个超越概率经济损失统计
            List<Map<String, Object>> economicLossMethodList=exportPGReportDataService.getEconomicLossMethod(taskId,input);
            policyMap.put("economicLossMethodList",rowTableRenderPolicy);
            paramMap.put("economicLossMethodList",economicLossMethodList);
        }

        // 3.2.地震人员受伤评估
        if(assess_obj!=null&&assess_obj.toString().contains("1")) {//人员
            DzzhDzryqkCustomTableMethodPolicy2 tableMethodPolicy = new DzzhDzryqkCustomTableMethodPolicy2();
            policyMap.put("dzzhDzryqkTableList1", tableMethodPolicy);
            policyMap.put("dzzhDzryqkTableList2", tableMethodPolicy);
            String inputMode = "0";
            if("1000000102".equals(inputNum)){
                inputMode = "1";
            }else if("1000000103".equals(inputNum)){
                inputMode = "2";
            }
            List<Map<String, Object>> dzzhDzryqkTableList1 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationEdForInjureDataList_Report2(taskId,inputMode);
            paramMap.put("dzzhDzryqkTableList1", dzzhDzryqkTableList1);
            // 3.3 地震人员死亡评估 表格策略
            List<Map<String, Object>> dzzhDzryqkTableList2 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationEdForDeathDataList_Report2(taskId,inputMode);
            paramMap.put("dzzhDzryqkTableList2", dzzhDzryqkTableList2);
        }
        paramMap.put("buildinDamageList",new ArrayList<>());
        createWordReport1(policyMap, paramMap, inputNum,bgId);
        logger.info("word报告生产成功");

        return resultMap;
    }

    //03确定评估-设定地震影响场数据生成
    @Override
    public Map<String, String> earthquakeEffectsWordReportData(String taskId, String bgId) throws Exception{
        Map<String, Object> paramMap = new HashMap<>();
        Map<String,String> resultMap = new HashMap<>();
        Map<String,RenderPolicy> policyMap = new HashMap<>();
        Map<String,Object> taskObj = getTaskObjById(taskId);
        String inputNum="1000000103";
        this.buildCommonReportParam(paramMap,policyMap,taskId,taskObj,inputNum,"3");
        //3.1地震影响场版本信息
        String influenceVersion = taskObj.get("influence_field_version").toString();
        //选择烈度衰减关系模型生成的影响场
        paramMap.put("announce1",false);
        paramMap.put("announce2",false);
        paramMap.put("announce3",false);
        List<Map<String, Object>> earthquakeEffects = exportPGReportDataService.getEarthquakeEffects(influenceVersion);
        Collections.sort(earthquakeEffects, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                // 根据"key"的值进行比较，假设它们都存在且为Integer类型
                return Integer.compare(Integer.parseInt(o1.get("dz_intensity").toString()), Integer.parseInt(o2.get("dz_intensity").toString()));
            }
        });
        if(earthquakeEffects!=null&&earthquakeEffects.size()>0){
            Map<String, Object> stringObjectMap = earthquakeEffects.get(0);
            paramMap.put("longitude",stringObjectMap.get("longitude"));//经度
            paramMap.put("latitude",stringObjectMap.get("latitude"));//纬度
            paramMap.put("magnitude",stringObjectMap.get("magnitude")+"级");//震级
            paramMap.put("direction",stringObjectMap.get("direction")+"度");//长轴方向
            paramMap.put("announce"+stringObjectMap.get("data_source"),true);
            for (Map<String, Object> earthquakeEffect : earthquakeEffects) {
                //3.2地震影响场数据 -各个烈度区域面积
                BigDecimal geom = exportPGReportDataService.getAreaByGeom(earthquakeEffect.get("geom1").toString()).setScale(2, RoundingMode.HALF_DOWN);
                earthquakeEffect.put("mianji",geom);
            }
        }
        policyMap.put("earthquakeEffectsList",rowTableRenderPolicy);
        paramMap.put("earthquakeEffectsList",earthquakeEffects);

        //4.1结构破坏评估-4.1.2建筑物破坏状态评估结果
        List<Map<String, Object>> buildinDamageList=exportPGReportDataService.getbuildinDamage(taskId,influenceVersion);
        List<Map<String, Object>> newBuildinDamageList = new ArrayList<>();
        Map<String,String> influencefliedMap = new HashMap<>(10);
        Map<String,String> influencefliedMap2 = new HashMap<>(10);
        if(PlatformObjectUtils.isNotEmpty(buildinDamageList) &&buildinDamageList.size()>0){
            List<SettingInfluenceFliedEntity> influencefliedList = seismicImpactFieldRepository.getInfluencefliedList(influenceVersion);
            for (SettingInfluenceFliedEntity settingInfluenceFliedEntity : influencefliedList) {
                influencefliedMap.put(settingInfluenceFliedEntity.getId(),settingInfluenceFliedEntity.getIntensityCh());
                influencefliedMap2.put(settingInfluenceFliedEntity.getId(),settingInfluenceFliedEntity.getDzIntensity());
            }
            for (Map<String, Object> stringObjectMap : buildinDamageList) {
                stringObjectMap.put("intensity",influencefliedMap.get(stringObjectMap.get("condition").toString()));
                stringObjectMap.put("dzIntensity",influencefliedMap2.get(stringObjectMap.get("condition").toString()));
//                switch (String.valueOf(stringObjectMap.get("condition"))){
//                    //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
//                    case "ld1": stringObjectMap.put("intensity","Ⅵ");break;
//                    case "ld2": stringObjectMap.put("intensity","Ⅶ");break;
//                    case "ld3": stringObjectMap.put("intensity","Ⅷ");break;
//                    case "ld4": stringObjectMap.put("intensity","Ⅸ");break;
//                    case "ld5": stringObjectMap.put("intensity","Ⅹ");break;
//                }
            }
            newBuildinDamageList = buildinDamageList.stream().sorted(Comparator.comparing(map -> Integer.parseInt(map.get("dzIntensity").toString()))).collect(Collectors.toList());
        }

        policyMap.put("buildinDamageList",rowTableRenderPolicy);
        paramMap.put("buildinDamageList",newBuildinDamageList);
        //4.4地震直接经济损失评估-4.4.2经济损失评估结果-1、按VI~X烈度下经济损失统计
        Object assess_obj = taskObj.get("assess_obj");
        if(assess_obj!=null&&assess_obj.toString().contains("2")) {//经济
            List<Map<String, Object>> economicLossList = exportPGReportDataService.getEconomicLoss(taskId,"31");
            policyMap.put("economicLossList", rowTableRenderPolicy);
            paramMap.put("economicLossList", economicLossList);
        }


        createWordReport1(policyMap, paramMap, inputNum,bgId);

        logger.info("word报告生产成功");

        return resultMap;
    }
    public void getReportPicture(Map<String, Object> paramMap, String taskId,Integer inputMethod) throws Exception{
        if (inputMethod == 1) getPictures(paramMap,taskId,"5");
        if (inputMethod == 2) getPictures(paramMap,taskId,"6");
    }
    //获取超图图件
    private void getPictures(Map<String, Object> paramMap, String taskId,String flag) throws Exception {
        Map<String,Object> picMap = graphService.buildCategoryGraphParamData(taskId,flag);
        if(picMap!=null){
            if("5".equals(flag) || "6".equals(flag)){
                picMap.forEach((k,v)->{
                    //paramMap.put(k,picMap.get(k));
                    try {
                        paramMap.put(k,PlatformObjectUtils.isNotEmpty(picMap.get(k))?(Pictures.ofStream(new FileInputStream((String)picMap.get(k)), PictureType.PNG).altMeta("图片不存在")
                                .size(553, 391).create()):null);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                });
            }else{
                List<Map<String, Object>> structure = new ArrayList<Map<String, Object>>();
                picMap.forEach((k,v)->{
//                if(!"structure".equals(k)){
                    if(!k.contains("gw")){
                        PictureRenderData picImg = null;
                        try {
                            picImg = PlatformObjectUtils.isNotEmpty(picMap.get(k))?(Pictures.ofStream(new FileInputStream((String)picMap.get(k)), PictureType.PNG).altMeta("图片不存在")
                                    .size(553, 391).create()):null;
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        paramMap.put(k,picImg);
                    }else{
                        //paramMap.put(k,picMap.get(k));
                        try {
                            paramMap.put(k,Pictures.ofStream(new FileInputStream((String)picMap.get(k)), PictureType.PNG).altMeta("图片不存在")
                                    .size(553, 391).create());
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }

//                    Map<String, Object> data = new HashMap<String, Object>(2);
//                    String name = k.split("_")[1];
//                    Integer index = Integer.parseInt(k.split("_")[2]);
//                    String title = (index+2)+"";
//                    title = "图1-1-"+title+" "+name;
//                    data.put("title",title);
//                    PictureRenderData picImg = null;
//                    try {
//                        picImg = Pictures.ofStream(new FileInputStream(v.toString()), PictureType.PNG).altMeta("图片不存在")
//                                .size(580, 380).create();
//                    } catch (FileNotFoundException e) {
//                        e.printStackTrace();
//                    }
//                    data.put("structurePicture",picImg);
//                    structure.add(data);
                    }
                });
//            paramMap.put("structure",structure)
            }
        }

    }
    private void getPicturesPlus(Map<String, Object> paramMap, String taskId,String flag,String[] years) throws Exception {
        Map<String, Object> picMap = graphService.buildCategoryGraphParamDataPlus(taskId, flag,years);
        picMap.forEach((k, v) -> {
            PictureRenderData picImg = null;
            try {
                picImg = PlatformObjectUtils.isNotEmpty(picMap.get(k)) ? (Pictures.ofStream(new FileInputStream((String) picMap.get(k)), PictureType.PNG).altMeta("图片不存在")
                        .size(580, 380).create()) : null;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                throw new RuntimeException("获取图件失败");
            }
            paramMap.put(k, picImg);
        });
    }
    //04概率评估-发生概率
//    @Override
//    public Map<String, String> probabilityWordReportData(String taskId, String bgId,String type) throws Exception{
//        Map<String, Object> paramMap = new HashMap<>();
//        Map<String,String> resultMap = new HashMap<>();
//        Map<String,RenderPolicy> policyMap = new HashMap<>();
//        Map<String,Object> taskObj = getTaskObjById(taskId);
//        String inputNum="1000000201";
//        String houseDataFlag = taskObj.get("house_data_flag").toString();
//        String flag = "";
//        //0表示公共图件，生命线工程的只有私有图件，不需要查询公共图件
//        if(org.apache.commons.lang3.StringUtils.isNotBlank(houseDataFlag)){
//            if("0".equals(houseDataFlag)){
//                flag = "0-0";
//            }else if("1".equals(houseDataFlag)){
//                flag = "0-1";
//            }
//        }
//        //04概率评估-发生概率私有的需要单独处理，此时值查询公用的
//        this.buildCommonReportParam(paramMap,policyMap,taskId,taskObj,inputNum,flag);
//        //2建筑物地震易损性--2.2易损性曲线
//
//        //4.1结构破坏评估-4.1.1建筑物破坏状态评估方法
//        List<Map<String, Object>> buildinDamageMethodList=exportPGReportDataService.getbuildinProbabilityDamage(taskId);
//        policyMap.put("buildinDamageList",rowTableRenderPolicy);
//        paramMap.put("buildinDamageList",buildinDamageMethodList);
//
//
//
//        Object assess_obj = taskObj.get("assess_obj");
//        Object years = taskObj.get("year");
//        String[] yearSplit =null;
//        if(years!=null&&org.apache.commons.lang3.StringUtils.isNotBlank(years.toString())){
//            yearSplit = years.toString().split(",");
//            if(assess_obj!=null&&assess_obj.toString().contains("2")){//经济
//                paramMap.put("assess_obj_flag_1",true);
//                //4.4.2经济损失评估结果-按行政区划统计分析四个超越概率经济损失统计
//                List<Map<String, Object>> economicLossMethodList=exportPGReportDataService.getEconomicLossProbabilityPlus(taskId,yearSplit);
//                this.commonTable(yearSplit,paramMap,economicLossMethodList,"economicLossMethodList");
//            }
//
//            // 3.2.地震人员受伤评估
//            if(assess_obj!=null&&assess_obj.toString().contains("1")) {//人员
//                paramMap.put("assess_obj_flag_2",true);
//                List<Map<String, Object>> dzzhDzryqkTableList1 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationPdForInjureDataList_Report4(taskId,yearSplit);
//                this.commonTable(yearSplit,paramMap,dzzhDzryqkTableList1,"dzzhDzryqkTableList1");
//                // 3.3 地震人员死亡评估 表格策略
//                List<Map<String, Object>> dzzhDzryqkTableList2 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationPdForDeathDataList_Report4(taskId,yearSplit);
//                this.commonTable(yearSplit,paramMap,dzzhDzryqkTableList2,"dzzhDzryqkTableList2");
//            }
//        }else{
//            paramMap.put("assess_obj_flag_1",false);
//            paramMap.put("assess_obj_flag_2",false);
//        }
//        yearSplit = years.toString().split(",");
//
//        //概率特有加载超图部分开始
//        getPicturesPlus(paramMap,taskId,"4",yearSplit);
//        //概率特有加载超图部分结束
//
//        //4地震灾害风险区划-4.1.2.1结构破坏
//        FxqhAssessPdQhResult param= new FxqhAssessPdQhResult();
//        param.setEstimateObj("0");
//        param.setTaskId(taskId);
////        param.setTaskId("f5f38c36dba9459a8790abd9be5a6ec9");
//
//        List<FxqhAssessPdQhResultVo> jgAssessEdQhList1=new ArrayList<>();
//        List<FxqhAssessPdQhResultVo> jgAssessEdQhList2=new ArrayList<>();
//        List<FxqhAssessPdQhResultVo> jgAssessEdQhList3=new ArrayList<>();
//        List<FxqhAssessPdQhResultVo> jgAssessEdQhList4=new ArrayList<>();
//        List<FxqhAssessPdQhResultVo> jgAssessEdQhList5=new ArrayList<>();
//        int jgld1count1=0,jgld1count2=0,jgld1count3=0,jgld1count4=0,jgld1count5=0;
//        int jgld2count1=0,jgld2count2=0,jgld2count3=0,jgld2count4=0,jgld2count5=0;
//        int jgld3count1=0,jgld3count2=0,jgld3count3=0,jgld3count4=0,jgld3count5=0;
//        int jgld4count1=0,jgld4count2=0,jgld4count3=0,jgld4count4=0,jgld4count5=0;
//        int jgld5count1=0,jgld5count2=0,jgld5count3=0,jgld5count4=0,jgld5count5=0;
//        List<FxqhAssessPdQhResultVo> jgAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
//        //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
//        insertList1(jgAssessEdQhList,jgAssessEdQhList1,jgAssessEdQhList2,jgAssessEdQhList3,jgAssessEdQhList4,jgAssessEdQhList5,yearSplit);
//        countMap1(jgAssessEdQhList1,jgld1count1,jgld1count2,jgld1count3,jgld1count4,jgld1count5,paramMap,"jgld1");
//        countMap1(jgAssessEdQhList2,jgld2count1,jgld2count2,jgld2count3,jgld2count4,jgld2count5,paramMap,"jgld2");
//        countMap1(jgAssessEdQhList3,jgld3count1,jgld3count2,jgld3count3,jgld3count4,jgld3count5,paramMap,"jgld3");
//        countMap1(jgAssessEdQhList4,jgld4count1,jgld4count2,jgld4count3,jgld4count4,jgld4count5,paramMap,"jgld4");
//        countMap1(jgAssessEdQhList5,jgld5count1,jgld5count2,jgld5count3,jgld5count4,jgld5count5,paramMap,"jgld5");
//        Map<String,Object> map=new HashMap();
//        map.put("jgld1",jgAssessEdQhList1);
//        map.put("jgld2",jgAssessEdQhList2);
//        map.put("jgld3",jgAssessEdQhList3);
//        map.put("jgld4",jgAssessEdQhList4);
//        map.put("jgld5",jgAssessEdQhList5);
//        paramMap.put("jgld1count1",jgld1count1);
//        paramMap.put("jgld2count1",jgld2count1);
//        paramMap.put("jgld3count1",jgld3count1);
//        paramMap.put("jgld4count1",jgld4count1);
//        paramMap.put("jgld5count1",jgld5count1);
//        paramMap.put("year_flag_0",true);
//        paramMap.put("year_flag_1",false);
//        paramMap.put("year_flag_2",false);
//        paramMap.put("year_flag_3",false);
//        paramMap.put("year_flag_4",false);
//        paramMap.put("year1","1");
//        for (int i = 0; i < yearSplit.length; i++) {
//            policyMap.put("jgAssessEdQhList"+(i+1), rowTableRenderPolicy);
//            paramMap.put("jgAssessEdQhList"+(i+1), map.get("jgld"+(i+1)));
//            paramMap.put("year"+i, yearSplit[i]);
//            paramMap.put("year_flag_"+i,true);
//        }
////        policyMap.put("jgAssessEdQhList1", rowTableRenderPolicy);
////        paramMap.put("jgAssessEdQhList1", jgAssessEdQhList1);
////        policyMap.put("jgAssessEdQhList2", rowTableRenderPolicy);
////        paramMap.put("jgAssessEdQhList2", jgAssessEdQhList2);
////        policyMap.put("jgAssessEdQhList3", rowTableRenderPolicy);
////        paramMap.put("jgAssessEdQhList3", jgAssessEdQhList3);
////        policyMap.put("jgAssessEdQhList4", rowTableRenderPolicy);
////        paramMap.put("jgAssessEdQhList4", jgAssessEdQhList4);
////        policyMap.put("jgAssessEdQhList5", rowTableRenderPolicy);
////        paramMap.put("jgAssessEdQhList5", jgAssessEdQhList5);
//
//        //4.1.2.2人员死亡
//        if(assess_obj!=null&&assess_obj.toString().contains("1")) {//人员
//            param.setEstimateObj("1");
//            List<FxqhAssessPdQhResultVo> swAssessEdQhList1 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> swAssessEdQhList2 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> swAssessEdQhList3 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> swAssessEdQhList4 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> swAssessEdQhList5 = new ArrayList<>();
//            int swld1count1 = 0, swld1count2 = 0, swld1count3 = 0, swld1count4 = 0, swld1count5 = 0;
//            int swld2count1 = 0, swld2count2 = 0, swld2count3 = 0, swld2count4 = 0, swld2count5 = 0;
//            int swld3count1 = 0, swld3count2 = 0, swld3count3 = 0, swld3count4 = 0, swld3count5 = 0;
//            int swld4count1 = 0, swld4count2 = 0, swld4count3 = 0, swld4count4 = 0, swld4count5 = 0;
//            int swld5count1 = 0, swld5count2 = 0, swld5count3 = 0, swld5count4 = 0, swld5count5 = 0;
//            List<FxqhAssessPdQhResultVo> swAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
//            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
//            insertList1(swAssessEdQhList, swAssessEdQhList1, swAssessEdQhList2, swAssessEdQhList3, swAssessEdQhList4, swAssessEdQhList5,yearSplit);
//            countMap1(swAssessEdQhList1, swld1count1, swld1count2, swld1count3, swld1count4, swld1count5, paramMap, "swld1");
//            countMap1(swAssessEdQhList2, swld2count1, swld2count2, swld2count3, swld2count4, swld2count5, paramMap, "swld2");
//            countMap1(swAssessEdQhList3, swld3count1, swld3count2, swld3count3, swld3count4, swld3count5, paramMap, "swld3");
//            countMap1(swAssessEdQhList4, swld4count1, swld4count2, swld4count3, swld4count4, swld4count5, paramMap, "swld4");
//            countMap1(swAssessEdQhList5, swld5count1, swld5count2, swld5count3, swld5count4, swld5count5, paramMap, "swld5");
//            Map<String,Object> map1=new HashMap();
//            paramMap.put("swld1count1",swld1count1);
//            paramMap.put("swld2count1",swld2count1);
//            paramMap.put("swld3count1",swld3count1);
//            paramMap.put("swld4count1",swld4count1);
//            paramMap.put("swld5count1",swld5count1);
//            map1.put("swld1",swAssessEdQhList1);
//            map1.put("swld2",swAssessEdQhList2);
//            map1.put("swld3",swAssessEdQhList3);
//            map1.put("swld4",swAssessEdQhList4);
//            map1.put("swld5",swAssessEdQhList5);
//            for (int i = 0; i < yearSplit.length; i++) {
//                policyMap.put("swAssessEdQhList"+(i+1), rowTableRenderPolicy);
//                paramMap.put("swAssessEdQhList"+(i+1), map1.get("swld"+(i+1)));
//            }
////            policyMap.put("swAssessEdQhList1", rowTableRenderPolicy);
////            paramMap.put("swAssessEdQhList1", swAssessEdQhList1);
////            policyMap.put("swAssessEdQhList2", rowTableRenderPolicy);
////            paramMap.put("swAssessEdQhList2", swAssessEdQhList2);
////            policyMap.put("swAssessEdQhList3", rowTableRenderPolicy);
////            paramMap.put("swAssessEdQhList3", swAssessEdQhList3);
////            policyMap.put("swAssessEdQhList4", rowTableRenderPolicy);
////            paramMap.put("swAssessEdQhList4", swAssessEdQhList4);
////            policyMap.put("swAssessEdQhList5", rowTableRenderPolicy);
////            paramMap.put("swAssessEdQhList5", swAssessEdQhList5);
//        }
//        //4.1.2.3经济损失
//        if(assess_obj!=null&&assess_obj.toString().contains("2")) {//经济
//            param.setEstimateObj("2");
//            List<FxqhAssessPdQhResultVo> jjAssessEdQhList1 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> jjAssessEdQhList2 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> jjAssessEdQhList3 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> jjAssessEdQhList4 = new ArrayList<>();
//            List<FxqhAssessPdQhResultVo> jjAssessEdQhList5 = new ArrayList<>();
//            int jjld1count1 = 0, jjld1count2 = 0, jjld1count3 = 0, jjld1count4 = 0, jjld1count5 = 0;
//            int jjld2count1 = 0, jjld2count2 = 0, jjld2count3 = 0, jjld2count4 = 0, jjld2count5 = 0;
//            int jjld3count1 = 0, jjld3count2 = 0, jjld3count3 = 0, jjld3count4 = 0, jjld3count5 = 0;
//            int jjld4count1 = 0, jjld4count2 = 0, jjld4count3 = 0, jjld4count4 = 0, jjld4count5 = 0;
//            int jjld5count1 = 0, jjld5count2 = 0, jjld5count3 = 0, jjld5count4 = 0, jjld5count5 = 0;
//            List<FxqhAssessPdQhResultVo> jjAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
//            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
//            insertList1(jjAssessEdQhList, jjAssessEdQhList1, jjAssessEdQhList2, jjAssessEdQhList3, jjAssessEdQhList4, jjAssessEdQhList5,yearSplit);
//            countMap1(jjAssessEdQhList1, jjld1count1, jjld1count2, jjld1count3, jjld1count4, jjld1count5, paramMap, "jjld1");
//            countMap1(jjAssessEdQhList2, jjld2count1, jjld2count2, jjld2count3, jjld2count4, jjld1count5, paramMap, "jjld2");
//            countMap1(jjAssessEdQhList3, jjld3count1, jjld3count2, jjld3count3, jjld3count4, jjld3count5, paramMap, "jjld3");
//            countMap1(jjAssessEdQhList4, jjld4count1, jjld4count2, jjld4count3, jjld4count4, jjld4count5, paramMap, "jjld4");
//            countMap1(jjAssessEdQhList5, jjld5count1, jjld5count2, jjld5count3, jjld5count4, jjld5count5, paramMap, "jjld5");
//            Map<String,Object> map1=new HashMap();
//            paramMap.put("jjld1count1",jjld1count1);
//            paramMap.put("jjld2count1",jjld2count1);
//            paramMap.put("jjld3count1",jjld3count1);
//            paramMap.put("jjld4count1",jjld4count1);
//            paramMap.put("jjld5count1",jjld5count1);
//            map1.put("jjld1",jjAssessEdQhList1);
//            map1.put("jjld2",jjAssessEdQhList2);
//            map1.put("jjld3",jjAssessEdQhList3);
//            map1.put("jjld4",jjAssessEdQhList4);
//            map1.put("jjld5",jjAssessEdQhList5);
//            for (int i = 0; i < yearSplit.length; i++) {
//                policyMap.put("jjAssessEdQhList"+(i+1), rowTableRenderPolicy);
//                paramMap.put("jjAssessEdQhList"+(i+1), map1.get("jjld"+(i+1)));
//            }
////            policyMap.put("jjAssessEdQhList1", rowTableRenderPolicy);
////            paramMap.put("jjAssessEdQhList1", jjAssessEdQhList1);
////            policyMap.put("jjAssessEdQhList2", rowTableRenderPolicy);
////            paramMap.put("jjAssessEdQhList2", jjAssessEdQhList2);
////            policyMap.put("jjAssessEdQhList3", rowTableRenderPolicy);
////            paramMap.put("jjAssessEdQhList3", jjAssessEdQhList3);
////            policyMap.put("jjAssessEdQhList4", rowTableRenderPolicy);
////            paramMap.put("jjAssessEdQhList4", jjAssessEdQhList4);
////            policyMap.put("jjAssessEdQhList5", rowTableRenderPolicy);
////            paramMap.put("jjAssessEdQhList5", jjAssessEdQhList5);
//        }
//
//        Map<String,Integer> zzMap = new HashMap<>();
//        paramMap.put("assess_obj_flag_6",false);
//        if(assess_obj!=null&&assess_obj.toString().contains("1")&&assess_obj.toString().contains("2")) {//如果3个都存在的话 则展示综合风险区划
//            paramMap.put("assess_obj_flag_6",true);
//            //4.2综合风险区划--4.2.2风险区划等级
//            QueryParam queryParam=new QueryParam();
//            queryParam.setId(taskId);
//            queryParam.setCategory("3");
//            List<PopulationAndLoss> zhjgAssessEdQhList1=new ArrayList<>();
//            List<PopulationAndLoss> zhjgAssessEdQhList2=new ArrayList<>();
//            List<PopulationAndLoss> zhjgAssessEdQhList3=new ArrayList<>();
//            List<PopulationAndLoss> zhjgAssessEdQhList4=new ArrayList<>();
//            List<PopulationAndLoss> zhjgAssessEdQhList5=new ArrayList<>();
//            int zhjgld1count1=0,zhjgld1count2=0,zhjgld1count3=0,zhjgld1count4=0,zhjgld1count5=0;
//            int zhjgld2count1=0,zhjgld2count2=0,zhjgld2count3=0,zhjgld2count4=0,zhjgld2count5=0;
//            int zhjgld3count1=0,zhjgld3count2=0,zhjgld3count3=0,zhjgld3count4=0,zhjgld3count5=0;
//            int zhjgld4count1=0,zhjgld4count2=0,zhjgld4count3=0,zhjgld4count4=0,zhjgld4count5=0;
//            int zhjgld5count1=0,zhjgld5count2=0,zhjgld5count3=0,zhjgld5count4=0,zhjgld5count5=0;
//            List<PopulationAndLoss> zhjgAssessEdQhList = this.getzhjgResult(queryParam);
//            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
//            insertListzh(zhjgAssessEdQhList, zhjgAssessEdQhList1, zhjgAssessEdQhList2, zhjgAssessEdQhList3, zhjgAssessEdQhList4, zhjgAssessEdQhList5,yearSplit);
//            countMap2(zhjgAssessEdQhList1,zhjgld1count1,zhjgld1count2,zhjgld1count3,zhjgld1count4,zhjgld1count5,zzMap,"zhjgld1");
//            paramMap.put("zhjgld1",getCount("zhjgld1",zzMap));
//            countMap2(zhjgAssessEdQhList2,zhjgld2count1,zhjgld2count2,zhjgld2count3,zhjgld2count4,zhjgld2count5,zzMap,"zhjgld2");
//            paramMap.put("zhjgld2",getCount("zhjgld2",zzMap));
//            countMap2(zhjgAssessEdQhList3,zhjgld3count1,zhjgld3count2,zhjgld3count3,zhjgld3count4,zhjgld3count5,zzMap,"zhjgld3");
//            paramMap.put("zhjgld3",getCount("zhjgld3",zzMap));
//            countMap2(zhjgAssessEdQhList4,zhjgld4count1,zhjgld4count2,zhjgld4count3,zhjgld4count4,zhjgld4count5,zzMap,"zhjgld4");
//            paramMap.put("zhjgld4",getCount("zhjgld4",zzMap));
//            countMap2(zhjgAssessEdQhList5,zhjgld5count1,zhjgld5count2,zhjgld5count3,zhjgld5count4,zhjgld5count5,zzMap,"zhjgld5");
//            paramMap.put("zhjgld5",getCount("zhjgld5",zzMap));
//            Map<String,Object> map1=new HashMap();
//            map1.put("zhjgld1",zhjgAssessEdQhList1);
//            map1.put("zhjgld2",zhjgAssessEdQhList2);
//            map1.put("zhjgld3",zhjgAssessEdQhList3);
//            map1.put("zhjgld4",zhjgAssessEdQhList4);
//            map1.put("zhjgld5",zhjgAssessEdQhList5);
//            for (int i = 0; i < yearSplit.length; i++) {
//                policyMap.put("zhjgAssessEdQhList"+(i+1), rowTableRenderPolicy);
//                paramMap.put("zhjgAssessEdQhList"+(i+1), map1.get("zhjgld"+(i+1)));
//            }
//
////            policyMap.put("zhjgAssessEdQhList2", rowTableRenderPolicy);
////            paramMap.put("zhjgAssessEdQhList2", zhjgAssessEdQhList2);
////            policyMap.put("zhjgAssessEdQhList3", rowTableRenderPolicy);
////            paramMap.put("zhjgAssessEdQhList3", zhjgAssessEdQhList3);
////            policyMap.put("zhjgAssessEdQhList4", rowTableRenderPolicy);
////            paramMap.put("zhjgAssessEdQhList4", zhjgAssessEdQhList4);
////            policyMap.put("zhjgAssessEdQhList5", rowTableRenderPolicy);
////            paramMap.put("zhjgAssessEdQhList5", zhjgAssessEdQhList5);
//        }
//        createWordReport1(policyMap, paramMap, inputNum,bgId);
//        logger.info("word报告生产成功");
//
//        return resultMap;
//    }

    @Override
    public Map<String, String> probabilityWordReportData1(String taskId, String bgId,String type) throws Exception{
        Map<String, Object> paramMap = new HashMap<>();
        Map<String,String> resultMap = new HashMap<>();
        Map<String,RenderPolicy> policyMap = new HashMap<>();
        String inputNum="1000000201";
        Map<String,Object> taskObj = getTaskObjById(taskId);
        //任务名称
        String taskName = taskObj.get("assess_name")+"";
        String houseDataFlag = taskObj.get("house_data_flag").toString();
        String flag = "";
        //0表示公共图件，生命线工程的只有私有图件，不需要查询公共图件
        if(org.apache.commons.lang3.StringUtils.isNotBlank(houseDataFlag)){
            if("0".equals(houseDataFlag)){
                flag = "0-0";
            }else if("1".equals(houseDataFlag)){
                flag = "0-1";
            }
        }
        //04概率评估-发生概率私有的需要单独处理，此时值查询公用的
        getPictures(paramMap,taskId,flag);

        //this.buildCommonReportParam(paramMap,policyMap,taskId,taskObj,inputNum,flag);
        //获取任务关联的省市县
        List<PCC> pccs = pccRepository.queryToponym(taskId);
        //单位名称
        String deptName="XX单位A";
        //创建时间
        String createTime=new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        paramMap.put("name",taskName);
        paramMap.put("deptName",deptName);
        paramMap.put("createTime",createTime);
        Object house_data_flag_v = taskObj.get("house_data_flag");
        //0为单体1为网格
        String house_data_flag="0";
        if(house_data_flag_v!=null){
            house_data_flag=house_data_flag_v.toString();
        }
        String buildingType="单体数据";
        String buildingTypeName="建筑物单体数据";
        paramMap.put("showGrid",true);
        //1.建筑物单体数据 /建筑物网格   ---各个结构类型的建筑面积
        List<ReportCommonData> dataList1 = new ArrayList<ReportCommonData>();
        //1.建筑物单体数据 /建筑物网格  --	各个设防情况下的建筑面积
        List<ReportCommonData> dataList2 = new ArrayList<ReportCommonData>();

        if("0".equals(house_data_flag)){
            //1.建筑物单体数据
            dataList1 = getBuildingIndividualCal(taskId);
            //2.建筑物单体数据 2)	各个设防情况下的建筑面积
            dataList2 = getBuildingIndividualSfqkCal(taskId);
            paramMap.put("showGrid",false);
        }else{
            //1.房屋网格数据
            dataList1 = getGridDataCal(taskId);
            //2.房屋网格 2)	各个设防情况下的建筑面积
            dataList2 = getGridDataSfqkCal(taskId);

            buildingTypeName="建筑物格网数据";
            buildingType="建筑物格网";
        }
        paramMap.put("showGrid",true);
        if("0".equals(house_data_flag)){
            //1.建筑物单体数据
            dataList1 = getBuildingIndividualCal(taskId);
            //2.建筑物单体数据 2)	各个设防情况下的建筑面积
            dataList2 = getBuildingIndividualSfqkCal(taskId);
            paramMap.put("showGrid",false);
        }else{
            //1.房屋网格数据
            dataList1 = getGridDataCal(taskId);
            //2.房屋网格 2)	各个设防情况下的建筑面积
            dataList2 = getGridDataSfqkCal(taskId);

            buildingTypeName="建筑物格网数据";
            buildingType="建筑物格网";
        }
        paramMap.put("buildingTypeName",buildingTypeName);
        paramMap.put("buildingType",buildingType);
        //结构类型面积柱状图
        String []categories=null;
        Double []seriesValue=null;

        String []categories2=null;
        Double []seriesValue2=null;
        if("0".equals(house_data_flag)){
            categories=new String[]{"钢结构","钢筋混凝土结构-剪力墙结构","钢筋混凝土结构-框架结构","钢筋混凝土结构-框架-剪力墙结构"};
            seriesValue = new Double[]{0D,0D,0D,0D};

            categories2 =new String[]{"未设防","6度","7度","8度","9度"};
            seriesValue2=new Double[]{0D,0D,0D,0D,0D};
        }else{
            categories=new String[]{"城镇钢混结构房屋格网","城镇钢结构房屋格网","城镇木结构房屋格网"};
            seriesValue = new Double[]{0D,0D,0D};

            categories2 =new String[]{"未设防","6度","7度","8度","9度"};
            seriesValue2=new Double[]{0D,0D,0D,0D,0D};
        }

        if(!dataList1.isEmpty()){
            categories=new String[dataList1.size()];
            seriesValue=new Double[dataList1.size()];
            for(int i=0;i<dataList1.size();i++){
                ReportCommonData data = dataList1.get(i);
                categories[i]=data.getDataName();
                try{
                    seriesValue[i]=Double.valueOf(PlatformObjectUtils.isNotEmpty(data.getDataValue())?data.getDataValue():"0");
                }catch (NullPointerException e){
                    e.printStackTrace();
                }

            }
        }

        ChartMultiSeriesRenderData barChart1 = Charts
                .ofMultiSeries(null, categories)
                .addSeries("", seriesValue)
                .create();
        paramMap.put("barChart1",barChart1);
        paramMap.put("dataList1",dataList1);
        if(dataList1.size()<13){
            Map<String, String> structureAreaMap = buildStructureArea();
            List<String> nameList = dataList1.stream().map(ReportCommonData::getDataName).collect(Collectors.toList());
            Iterator<String> iterator = structureAreaMap.keySet().iterator();
            while(iterator.hasNext()){
                String key = iterator.next();
                if(!nameList.contains(key)){
                    ReportCommonData reportCommonData = new ReportCommonData();
                    reportCommonData.setDataName(key);
                    reportCommonData.setDataValue(structureAreaMap.get(key));
                    dataList1.add(reportCommonData);
                }
            }
        }
        List<Map<String,Object>> resetPriceList = new ArrayList<>();
        if(PlatformObjectUtils.isNotEmpty(pccs) && pccs.size()>0){
            for (PCC pcc : pccs) {
                List<Map<String,Object>> list = getFxqhBuildingPriceTask(pcc);
                if(PlatformObjectUtils.isNotEmpty(list) && list.size()>0){
                    resetPriceList.addAll(list);
                }
            }
        }
        paramMap.put("dataList2",dataList2);
        paramMap.put("resetPriceList",resetPriceList);
        policyMap.put("resetPriceList",rowTableRenderPolicy);
        if(!dataList2.isEmpty()) {
            categories2 = new String[dataList2.size()];
            seriesValue2 = new Double[dataList2.size()];
            for (int i = 0; i < dataList2.size(); i++) {
                ReportCommonData data = dataList2.get(i);
                categories2[i] = data.getDataName();
                seriesValue2[i] = Double.valueOf(data.getDataValue());
            }
        }
        ChartMultiSeriesRenderData barChart2 = Charts
                .ofMultiSeries(null, categories2)
                .addSeries("", seriesValue2)
                .create();
        paramMap.put("barChart2",barChart2);
        //人口只有任务创建时选择了人员伤亡评估时才展示
        paramMap.put("assess_obj_flag_1",false);
        //GDP只有任务创建时选择了经济损失评估时才展示
        paramMap.put("assess_obj_flag_2",false);
        Object assess_obj = taskObj.get("assess_obj");
        Object years = taskObj.get("year");
        String[] yearSplit =null;
        yearSplit = years.toString().split(",");
        String geom = publicOperateService.getDistrictGeom(taskObj);
        Map<String,Integer> jjssMap = new HashMap<>();
        if(assess_obj!=null&&assess_obj.toString().contains("2")){//经济
            paramMap.put("assess_obj_flag_1",true);
            //获取任务区域内的gdp
            JSONObject gdp = jcsjRestManager.getGdp(geom, taskObj.get("gdp_version").toString());
            if(PlatformObjectUtils.isNotEmpty(gdp.get("data"))){
                paramMap.put("GDP",new BigDecimal(gdp.get("data").toString()));
            }else {
                paramMap.put("GDP",BigDecimal.ZERO);
            }
            final BigDecimal[] previousGdp = {BigDecimal.ZERO};
            //获取上一年的gdp
            pccs.forEach(pcc ->{
                GdpVO gdpData = enterAssessQhRepository.getGdpByTaskIdAndDistrict(taskId,pcc.getPpName(),pcc.getCityName(),pcc.getName());
                if(gdpData != null ){
                    previousGdp[0] = previousGdp[0].add(gdpData.getPreviousGdp());
                }

            });
            paramMap.put("previousGdp", previousGdp[0]);
            //4.4.2经济损失评估结果-按行政区划统计分析四个超越概率经济损失统计
            List<Map<String, Object>> economicLossMethodList=exportPGReportDataService.getEconomicLossProbabilityPlus(taskId,yearSplit);
            this.commonTable(yearSplit,paramMap,economicLossMethodList,"economicLossMethodList");
            FxqhAssessPdQhResult param= new FxqhAssessPdQhResult();
            param.setEstimateObj("0");
            param.setTaskId(taskId);
            param.setEstimateObj("2");
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList1 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList2 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList3 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList4 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList5 = new ArrayList<>();
            int jjld1count1 = 0, jjld1count2 = 0, jjld1count3 = 0, jjld1count4 = 0, jjld1count5 = 0;
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
            //List<FxqhAssessEdQhResultVo> jjAssessEdQhList = enterAssessQhService.getAssessEdQhList(param, null, null);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList3(jjAssessEdQhList, jjAssessEdQhList1, jjAssessEdQhList2, jjAssessEdQhList3, jjAssessEdQhList4, jjAssessEdQhList5,type);
            countMap3(jjAssessEdQhList1, jjld1count1, jjld1count2, jjld1count3, jjld1count4, jjld1count5, jjssMap, "jjld1");
            paramMap.put("jjld1",getCount("jjld1", jjssMap));
            paramMap.put("jjAssessEdQhList1",jjAssessEdQhList1);
            policyMap.put("jjAssessEdQhList1",rowTableRenderPolicy);
        }

        // 3.2.地震人员受伤评估
        if(assess_obj!=null&&assess_obj.toString().contains("1")) {//人员
            Map<String,Integer> ryswMap = new HashMap<>();
            paramMap.put("assess_obj_flag_2",true);
            //获取评估区域内人口总数
            Map<String,String> parMap = new HashMap<>();
            parMap.put("geom",geom);
            //parMap.put("dataVersion","JC02RKSJ20240222001");
            parMap.put("dataVersion",taskObj.get("popluation_version").toString());
            JcPopulationGridBo bo = jcsjRestManager.getJcPopulationGridGetByGeom(parMap);
            if(PlatformObjectUtils.isNotEmpty(bo.getData()) && bo.getCode()==200){
                paramMap.put("tzl3",new BigDecimal(bo.getData()).divide(new BigDecimal(10000),4,RoundingMode.HALF_DOWN));
            }else{
                paramMap.put("tzl3",0);
            }
            List<Map<String, Object>> dzzhDzryqkTableList1 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationPdForInjureDataList_Report4(taskId,yearSplit);
            this.commonTable(yearSplit,paramMap,dzzhDzryqkTableList1,"dzzhDzryqkTableList1");
            // 3.3 地震人员死亡评估 表格策略
            List<Map<String, Object>> dzzhDzryqkTableList2 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationPdForDeathDataList_Report4(taskId,yearSplit);
            this.commonTable(yearSplit,paramMap,dzzhDzryqkTableList2,"dzzhDzryqkTableList2");
            FxqhAssessPdQhResult param= new FxqhAssessPdQhResult();
            param.setEstimateObj("0");
            param.setTaskId(taskId);
            param.setEstimateObj("1");
            List<FxqhAssessPdQhResultVo> swAssessEdQhList1 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList2 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList3 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList4 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList5 = new ArrayList<>();
            int swld1count1 = 0, swld1count2 = 0, swld1count3 = 0, swld1count4 = 0, swld1count5 = 0;
            List<FxqhAssessPdQhResultVo> swAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
            //List<FxqhAssessEdQhResultVo> swAssessEdQhList = enterAssessQhService.getAssessEdQhList(param, null, null);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList3(swAssessEdQhList, swAssessEdQhList1, swAssessEdQhList2, swAssessEdQhList3, swAssessEdQhList4, swAssessEdQhList5,type);
            countMap3(swAssessEdQhList1, swld1count1, swld1count2, swld1count3, swld1count4, swld1count5, ryswMap, "swld1");
            String swld1 = getCount("swld1", ryswMap);
            paramMap.put("swld1",swld1);
            policyMap.put("swAssessEdQhList1", rowTableRenderPolicy);
            paramMap.put("swAssessEdQhList1", swAssessEdQhList1);
        }
        //4.1结构破坏评估-4.1.1建筑物破坏状态评估方法
        List<Map<String, Object>> buildinDamageMethodList=exportPGReportDataService.getbuildinProbabilityDamage(taskId);
        policyMap.put("buildinDamageList",rowTableRenderPolicy);
        paramMap.put("buildinDamageList",buildinDamageMethodList);
        //概率特有加载超图部分开始
        getPicturesPlus(paramMap,taskId,"4",yearSplit);
        policyMap.put("customTableList",customTableMethodPolicy);
        List<ReportYsxVO> reportYsxDataList = getReportYsxDataList(taskId);
        List<Map<String,Object>> reportYsxes = buildReportYsxData(reportYsxDataList);
        //List<Map<String,Object>> customTableList=getBuildingJzwysxDataList(taskId);
        paramMap.put("customTableList",reportYsxes);
        //3.1.1风险等级分级指标
        List<Map<String, Object>> qhmapsList = selectByTypeList("1","4","5");
        for (Map<String, Object> map : qhmapsList) {
            switch (map.get("type").toString()){
                case "1": map.put("type","结构破坏");break;
                case "4": map.put("type","经济损失");break;
                case "5": map.put("type","经济损失（新疆、青海和西藏地区）");break;
            }
        }
        List<Map<String, Object>> personmapsList = selectPersonByTypeList("2","3");
        for (Map<String, Object> map : personmapsList) {
            switch (map.get("type").toString()){
                case "2": map.put("type","人员死亡");break;
                case "3": map.put("type","人员死亡（新疆、青海和西藏地区）");break;
            }
        }
        qhmapsList.addAll(personmapsList);
        policyMap.put("qhmapsList", rowTableRenderPolicy);
        paramMap.put("qhmapsList", qhmapsList);
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList1=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList2=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList3=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList4=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList5=new ArrayList<>();
        int jgld1count1=0,jgld1count2=0,jgld1count3=0,jgld1count4=0,jgld1count5=0;
        FxqhAssessPdQhResult param= new FxqhAssessPdQhResult();
        param.setEstimateObj("0");
        param.setTaskId(taskId);
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
        //List<FxqhAssessEdQhResultVo> jgAssessEdQhList = enterAssessQhService.getAssessEdQhList(param, null, null);
        //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
        StringBuilder jjphsb = new StringBuilder("风险等级");
        Map<String,Integer> jgMap = new HashMap<>();
        insertList3(jgAssessEdQhList,jgAssessEdQhList1,jgAssessEdQhList2,jgAssessEdQhList3,jgAssessEdQhList4,jgAssessEdQhList5,type);
        countMap3(jgAssessEdQhList,jgld1count1,jgld1count2,jgld1count3,jgld1count4,jgld1count5,jgMap,"jgld1");
        Integer jgld1count11 = jgMap.get("jgld1count1");
        if(jgld1count11>0){
            jjphsb.append("I级区县").append(jgld1count11).append("个,");
        }
        Integer jgld1count12 = jgMap.get("jgld1count2");
        if(jgld1count12>0){
            jjphsb.append("II级区县").append(jgld1count12).append("个,");
        }
        Integer jgld1count13 = jgMap.get("jgld1count3");
        if(jgld1count13>0){
            jjphsb.append("III级区县").append(jgld1count13).append("个,");
        }
        Integer jgld1count14 = jgMap.get("jgld1count4");
        if(jgld1count14>0){
            jjphsb.append("IV级区县").append(jgld1count14).append("个,");
        }
        Integer jgld1count15 = jgMap.get("jgld1count5");
        if(jgld1count15>0){
            jjphsb.append("V级区县").append(jgld1count15).append("个,");
        }
        String jjph = jjphsb.toString();
        if(jjph.endsWith(",")){
            jjph = jjph.substring(0,jjph.lastIndexOf(","));
        }
        paramMap.put("jjph1",jjph);
        policyMap.put("jgAssessEdQhList1", rowTableRenderPolicy);
        paramMap.put("jgAssessEdQhList1", jgAssessEdQhList1);
        paramMap.put("assess_obj_flag_6",false);
        Map<String,Integer> zzMap = new HashMap<>();
        QueryParam queryParam=new QueryParam();
        queryParam.setId(taskId);
        queryParam.setCategory("3");
        if(assess_obj!=null&&assess_obj.toString().contains("1")&&assess_obj.toString().contains("2")&&assess_obj.toString().contains("0")){//如果3个都存在的话 则展示综合风险区划
            paramMap.put("assess_obj_flag_6",true);
            //4.2综合风险区划--4.2.1区划方法
            List<Map<String, Object>> zhqhmapsList = selectzhByTypeList("1","4","5");
            for (Map<String, Object> map : zhqhmapsList) {
                switch (map.get("type").toString()){
                    case "1": map.put("type","结构破坏");break;
                    case "4": map.put("type","经济损失");break;
                    case "5": map.put("type","经济损失（新疆、青海和西藏地区）");break;
                }
            }
            List<Map<String, Object>> personZhqhmapsList = selectPersonZhByTypeList("2","3");
            for (Map<String, Object> map : personZhqhmapsList) {
                switch (map.get("type").toString()){
                    case "2": map.put("type","人员死亡");break;
                    case "3": map.put("type","人员死亡（新疆、青海和西藏地区）");break;
                }
            }
            if(PlatformObjectUtils.isNotEmpty(personZhqhmapsList)){
                zhqhmapsList.addAll(personZhqhmapsList);
            }
            policyMap.put("zhqhmapsList", rowTableRenderPolicy);
            paramMap.put("zhqhmapsList", zhqhmapsList);

            List<PopulationAndLoss> zhjgAssessEdQhList1=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList2=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList3=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList4=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList5=new ArrayList<>();
            int zhjgld1count1=0,zhjgld1count2=0,zhjgld1count3=0,zhjgld1count4=0,zhjgld1count5=0;
            List<PopulationAndLoss> zhjgAssessEdQhList = this.getzhjgResult(queryParam);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList2(zhjgAssessEdQhList,zhjgAssessEdQhList1,zhjgAssessEdQhList2,zhjgAssessEdQhList3,zhjgAssessEdQhList4,zhjgAssessEdQhList5);
            countMap2(zhjgAssessEdQhList1,zhjgld1count1,zhjgld1count2,zhjgld1count3,zhjgld1count4,zhjgld1count5,zzMap,"zhjgld1");
            paramMap.put("zhjgld1", getCount("zhjgld1",zzMap));
            paramMap.put("zhjgAssessEdQhList1",zhjgAssessEdQhList1);
            policyMap.put("zhjgAssessEdQhList1", rowTableRenderPolicy);
        }
        createWordReport1(policyMap, paramMap, inputNum,bgId);
        return resultMap;

    }
    @Override
    public Map<String, String> probabilityWordReportData(String taskId, String bgId,String type) throws Exception{
        Map<String, Object> paramMap = new HashMap<>();
        Map<String,String> resultMap = new HashMap<>();
        Map<String,RenderPolicy> policyMap = new HashMap<>();
        Map<String,Object> taskObj = getTaskObjById(taskId);
        String inputNum="1000000201";
        String houseDataFlag = taskObj.get("house_data_flag").toString();
        String flag = "";
        //0表示公共图件，生命线工程的只有私有图件，不需要查询公共图件
        if(org.apache.commons.lang3.StringUtils.isNotBlank(houseDataFlag)){
            if("0".equals(houseDataFlag)){
                flag = "0-0";
            }else if("1".equals(houseDataFlag)){
                flag = "0-1";
            }
        }
        //04概率评估-发生概率私有的需要单独处理，此时值查询公用的

        this.buildCommonReportParam(paramMap,policyMap,taskId,taskObj,inputNum,flag);
        //2建筑物地震易损性--2.2易损性曲线

        Object assess_obj = taskObj.get("assess_obj");
        //人口只有任务创建时选择了人员伤亡评估时才展示
        paramMap.put("assess_obj_flag_1",false);
        //GDP只有任务创建时选择了经济损失评估时才展示
        paramMap.put("assess_obj_flag_2",false);
        Object years = taskObj.get("year");
        String[] yearSplit =null;
        yearSplit = years.toString().split(",");
        if(assess_obj!=null&&assess_obj.toString().contains("2")){//经济
            paramMap.put("assess_obj_flag_1",true);
            //4.4.2经济损失评估结果-按行政区划统计分析四个超越概率经济损失统计
            List<Map<String, Object>> economicLossMethodList=exportPGReportDataService.getEconomicLossProbabilityPlus(taskId,yearSplit);
            this.commonTable(yearSplit,paramMap,economicLossMethodList,"economicLossMethodList");
        }

        // 3.2.地震人员受伤评估
        if(assess_obj!=null&&assess_obj.toString().contains("1")) {//人员
            paramMap.put("assess_obj_flag_2",true);
            List<Map<String, Object>> dzzhDzryqkTableList1 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationPdForInjureDataList_Report4(taskId,yearSplit);
            this.commonTable(yearSplit,paramMap,dzzhDzryqkTableList1,"dzzhDzryqkTableList1");
            // 3.3 地震人员死亡评估 表格策略
            List<Map<String, Object>> dzzhDzryqkTableList2 = pgbgZdryqkReportService.getFxqhCasualtiesCalculationPdForDeathDataList_Report4(taskId,yearSplit);
            this.commonTable(yearSplit,paramMap,dzzhDzryqkTableList2,"dzzhDzryqkTableList2");
        }

        yearSplit = years.toString().split(",");

        //概率特有加载超图部分开始
        getPicturesPlus(paramMap,taskId,"4",yearSplit);
        //概率特有加载超图部分结束
        //4.1结构破坏评估-4.1.1建筑物破坏状态评估方法
        List<Map<String, Object>> buildinDamageMethodList=exportPGReportDataService.getbuildinProbabilityDamage(taskId);
        policyMap.put("buildinDamageList",rowTableRenderPolicy);
        paramMap.put("buildinDamageList",buildinDamageMethodList);
        //4地震灾害风险区划-4.1.2.1结构破坏
        FxqhAssessPdQhResult param= new FxqhAssessPdQhResult();
        param.setEstimateObj("0");
        param.setTaskId(taskId);
//        param.setTaskId("f5f38c36dba9459a8790abd9be5a6ec9");

        List<FxqhAssessPdQhResultVo> jgAssessEdQhList1=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList2=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList3=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList4=new ArrayList<>();
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList5=new ArrayList<>();
        int jgld1count1=0,jgld1count2=0,jgld1count3=0,jgld1count4=0,jgld1count5=0;
        int jgld2count1=0,jgld2count2=0,jgld2count3=0,jgld2count4=0,jgld2count5=0;
        int jgld3count1=0,jgld3count2=0,jgld3count3=0,jgld3count4=0,jgld3count5=0;
        int jgld4count1=0,jgld4count2=0,jgld4count3=0,jgld4count4=0,jgld4count5=0;
        int jgld5count1=0,jgld5count2=0,jgld5count3=0,jgld5count4=0,jgld5count5=0;
        List<FxqhAssessPdQhResultVo> jgAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
        //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
        insertList1(jgAssessEdQhList,jgAssessEdQhList1,jgAssessEdQhList2,jgAssessEdQhList3,jgAssessEdQhList4,jgAssessEdQhList5,yearSplit);
        countMap1(jgAssessEdQhList1,jgld1count1,jgld1count2,jgld1count3,jgld1count4,jgld1count5,paramMap,"jgld1");
        countMap1(jgAssessEdQhList2,jgld2count1,jgld2count2,jgld2count3,jgld2count4,jgld2count5,paramMap,"jgld2");
        countMap1(jgAssessEdQhList3,jgld3count1,jgld3count2,jgld3count3,jgld3count4,jgld3count5,paramMap,"jgld3");
        countMap1(jgAssessEdQhList4,jgld4count1,jgld4count2,jgld4count3,jgld4count4,jgld4count5,paramMap,"jgld4");
        countMap1(jgAssessEdQhList5,jgld5count1,jgld5count2,jgld5count3,jgld5count4,jgld5count5,paramMap,"jgld5");
        Map<String,Object> map=new HashMap();
        map.put("jgld1",jgAssessEdQhList1);
        map.put("jgld2",jgAssessEdQhList2);
        map.put("jgld3",jgAssessEdQhList3);
        map.put("jgld4",jgAssessEdQhList4);
        map.put("jgld5",jgAssessEdQhList5);
        paramMap.put("jgld1count1",jgld1count1);
        paramMap.put("jgld2count1",jgld2count1);
        paramMap.put("jgld3count1",jgld3count1);
        paramMap.put("jgld4count1",jgld4count1);
        paramMap.put("jgld5count1",jgld5count1);
//        paramMap.put("year_flag_0",false);
//        paramMap.put("year_flag_1",false);
//        paramMap.put("year_flag_2",false);
//        paramMap.put("year_flag_3",false);
//        paramMap.put("year_flag_4",false);
        //paramMap.put("year1","1");
        for (int i = 0; i < yearSplit.length; i++) {
            policyMap.put("jgAssessEdQhList"+(i+1), rowTableRenderPolicy);
            paramMap.put("jgAssessEdQhList"+(i+1), map.get("jgld"+(i+1)));
            paramMap.put("year"+i, yearSplit[i]);
            paramMap.put("year_flag_"+i,true);
        }
//        policyMap.put("jgAssessEdQhList1", rowTableRenderPolicy);
//        paramMap.put("jgAssessEdQhList1", jgAssessEdQhList1);
//        policyMap.put("jgAssessEdQhList2", rowTableRenderPolicy);
//        paramMap.put("jgAssessEdQhList2", jgAssessEdQhList2);
//        policyMap.put("jgAssessEdQhList3", rowTableRenderPolicy);
//        paramMap.put("jgAssessEdQhList3", jgAssessEdQhList3);
//        policyMap.put("jgAssessEdQhList4", rowTableRenderPolicy);
//        paramMap.put("jgAssessEdQhList4", jgAssessEdQhList4);
//        policyMap.put("jgAssessEdQhList5", rowTableRenderPolicy);
//        paramMap.put("jgAssessEdQhList5", jgAssessEdQhList5);

        //4.1.2.2人员死亡
        if(assess_obj!=null&&assess_obj.toString().contains("1")) {//人员
            param.setEstimateObj("1");
            List<FxqhAssessPdQhResultVo> swAssessEdQhList1 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList2 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList3 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList4 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> swAssessEdQhList5 = new ArrayList<>();
            int swld1count1 = 0, swld1count2 = 0, swld1count3 = 0, swld1count4 = 0, swld1count5 = 0;
            int swld2count1 = 0, swld2count2 = 0, swld2count3 = 0, swld2count4 = 0, swld2count5 = 0;
            int swld3count1 = 0, swld3count2 = 0, swld3count3 = 0, swld3count4 = 0, swld3count5 = 0;
            int swld4count1 = 0, swld4count2 = 0, swld4count3 = 0, swld4count4 = 0, swld4count5 = 0;
            int swld5count1 = 0, swld5count2 = 0, swld5count3 = 0, swld5count4 = 0, swld5count5 = 0;
            List<FxqhAssessPdQhResultVo> swAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList1(swAssessEdQhList, swAssessEdQhList1, swAssessEdQhList2, swAssessEdQhList3, swAssessEdQhList4, swAssessEdQhList5,yearSplit);
            countMap1(swAssessEdQhList1, swld1count1, swld1count2, swld1count3, swld1count4, swld1count5, paramMap, "swld1");
            countMap1(swAssessEdQhList2, swld2count1, swld2count2, swld2count3, swld2count4, swld2count5, paramMap, "swld2");
            countMap1(swAssessEdQhList3, swld3count1, swld3count2, swld3count3, swld3count4, swld3count5, paramMap, "swld3");
            countMap1(swAssessEdQhList4, swld4count1, swld4count2, swld4count3, swld4count4, swld4count5, paramMap, "swld4");
            countMap1(swAssessEdQhList5, swld5count1, swld5count2, swld5count3, swld5count4, swld5count5, paramMap, "swld5");
            Map<String,Object> map1=new HashMap();
            paramMap.put("swld1count1",swld1count1);
            paramMap.put("swld2count1",swld2count1);
            paramMap.put("swld3count1",swld3count1);
            paramMap.put("swld4count1",swld4count1);
            paramMap.put("swld5count1",swld5count1);
            map1.put("swld1",swAssessEdQhList1);
            map1.put("swld2",swAssessEdQhList2);
            map1.put("swld3",swAssessEdQhList3);
            map1.put("swld4",swAssessEdQhList4);
            map1.put("swld5",swAssessEdQhList5);
            for (int i = 0; i < yearSplit.length; i++) {
                policyMap.put("swAssessEdQhList"+(i+1), rowTableRenderPolicy);
                paramMap.put("swAssessEdQhList"+(i+1), map1.get("swld"+(i+1)));
            }
//            policyMap.put("swAssessEdQhList1", rowTableRenderPolicy);
//            paramMap.put("swAssessEdQhList1", swAssessEdQhList1);
//            policyMap.put("swAssessEdQhList2", rowTableRenderPolicy);
//            paramMap.put("swAssessEdQhList2", swAssessEdQhList2);
//            policyMap.put("swAssessEdQhList3", rowTableRenderPolicy);
//            paramMap.put("swAssessEdQhList3", swAssessEdQhList3);
//            policyMap.put("swAssessEdQhList4", rowTableRenderPolicy);
//            paramMap.put("swAssessEdQhList4", swAssessEdQhList4);
//            policyMap.put("swAssessEdQhList5", rowTableRenderPolicy);
//            paramMap.put("swAssessEdQhList5", swAssessEdQhList5);
        }
        //4.1.2.3经济损失
        if(assess_obj!=null&&assess_obj.toString().contains("2")) {//经济
            param.setEstimateObj("2");
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList1 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList2 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList3 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList4 = new ArrayList<>();
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList5 = new ArrayList<>();
            int jjld1count1 = 0, jjld1count2 = 0, jjld1count3 = 0, jjld1count4 = 0, jjld1count5 = 0;
            int jjld2count1 = 0, jjld2count2 = 0, jjld2count3 = 0, jjld2count4 = 0, jjld2count5 = 0;
            int jjld3count1 = 0, jjld3count2 = 0, jjld3count3 = 0, jjld3count4 = 0, jjld3count5 = 0;
            int jjld4count1 = 0, jjld4count2 = 0, jjld4count3 = 0, jjld4count4 = 0, jjld4count5 = 0;
            int jjld5count1 = 0, jjld5count2 = 0, jjld5count3 = 0, jjld5count4 = 0, jjld5count5 = 0;
            List<FxqhAssessPdQhResultVo> jjAssessEdQhList = probabilityAssessQhService.getAssessPdQhList(param);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList1(jjAssessEdQhList, jjAssessEdQhList1, jjAssessEdQhList2, jjAssessEdQhList3, jjAssessEdQhList4, jjAssessEdQhList5,yearSplit);
            countMap1(jjAssessEdQhList1, jjld1count1, jjld1count2, jjld1count3, jjld1count4, jjld1count5, paramMap, "jjld1");
            countMap1(jjAssessEdQhList2, jjld2count1, jjld2count2, jjld2count3, jjld2count4, jjld1count5, paramMap, "jjld2");
            countMap1(jjAssessEdQhList3, jjld3count1, jjld3count2, jjld3count3, jjld3count4, jjld3count5, paramMap, "jjld3");
            countMap1(jjAssessEdQhList4, jjld4count1, jjld4count2, jjld4count3, jjld4count4, jjld4count5, paramMap, "jjld4");
            countMap1(jjAssessEdQhList5, jjld5count1, jjld5count2, jjld5count3, jjld5count4, jjld5count5, paramMap, "jjld5");
            Map<String,Object> map1=new HashMap();
            paramMap.put("jjld1count1",jjld1count1);
            paramMap.put("jjld2count1",jjld2count1);
            paramMap.put("jjld3count1",jjld3count1);
            paramMap.put("jjld4count1",jjld4count1);
            paramMap.put("jjld5count1",jjld5count1);
            map1.put("jjld1",jjAssessEdQhList1);
            map1.put("jjld2",jjAssessEdQhList2);
            map1.put("jjld3",jjAssessEdQhList3);
            map1.put("jjld4",jjAssessEdQhList4);
            map1.put("jjld5",jjAssessEdQhList5);
            for (int i = 0; i < yearSplit.length; i++) {
                policyMap.put("jjAssessEdQhList"+(i+1), rowTableRenderPolicy);
                paramMap.put("jjAssessEdQhList"+(i+1), map1.get("jjld"+(i+1)));
            }
//            policyMap.put("jjAssessEdQhList1", rowTableRenderPolicy);
//            paramMap.put("jjAssessEdQhList1", jjAssessEdQhList1);
//            policyMap.put("jjAssessEdQhList2", rowTableRenderPolicy);
//            paramMap.put("jjAssessEdQhList2", jjAssessEdQhList2);
//            policyMap.put("jjAssessEdQhList3", rowTableRenderPolicy);
//            paramMap.put("jjAssessEdQhList3", jjAssessEdQhList3);
//            policyMap.put("jjAssessEdQhList4", rowTableRenderPolicy);
//            paramMap.put("jjAssessEdQhList4", jjAssessEdQhList4);
//            policyMap.put("jjAssessEdQhList5", rowTableRenderPolicy);
//            paramMap.put("jjAssessEdQhList5", jjAssessEdQhList5);
        }

        Map<String,Integer> zzMap = new HashMap<>();
        paramMap.put("assess_obj_flag_6",false);
        if(assess_obj!=null&&assess_obj.toString().contains("1")&&assess_obj.toString().contains("2")) {//如果3个都存在的话 则展示综合风险区划
            paramMap.put("assess_obj_flag_6",true);
            //4.2综合风险区划--4.2.2风险区划等级
            QueryParam queryParam=new QueryParam();
            queryParam.setId(taskId);
            queryParam.setCategory("3");
            List<PopulationAndLoss> zhjgAssessEdQhList1=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList2=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList3=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList4=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList5=new ArrayList<>();
            int zhjgld1count1=0,zhjgld1count2=0,zhjgld1count3=0,zhjgld1count4=0,zhjgld1count5=0;
            int zhjgld2count1=0,zhjgld2count2=0,zhjgld2count3=0,zhjgld2count4=0,zhjgld2count5=0;
            int zhjgld3count1=0,zhjgld3count2=0,zhjgld3count3=0,zhjgld3count4=0,zhjgld3count5=0;
            int zhjgld4count1=0,zhjgld4count2=0,zhjgld4count3=0,zhjgld4count4=0,zhjgld4count5=0;
            int zhjgld5count1=0,zhjgld5count2=0,zhjgld5count3=0,zhjgld5count4=0,zhjgld5count5=0;
            List<PopulationAndLoss> zhjgAssessEdQhList = this.getzhjgResult(queryParam);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertListzh(zhjgAssessEdQhList, zhjgAssessEdQhList1, zhjgAssessEdQhList2, zhjgAssessEdQhList3, zhjgAssessEdQhList4, zhjgAssessEdQhList5,yearSplit);
            countMap2(zhjgAssessEdQhList1,zhjgld1count1,zhjgld1count2,zhjgld1count3,zhjgld1count4,zhjgld1count5,zzMap,"zhjgld1");
            paramMap.put("zhjgld1",getCount("zhjgld1",zzMap));
            countMap2(zhjgAssessEdQhList2,zhjgld2count1,zhjgld2count2,zhjgld2count3,zhjgld2count4,zhjgld2count5,zzMap,"zhjgld2");
            paramMap.put("zhjgld2",getCount("zhjgld2",zzMap));
            countMap2(zhjgAssessEdQhList3,zhjgld3count1,zhjgld3count2,zhjgld3count3,zhjgld3count4,zhjgld3count5,zzMap,"zhjgld3");
            paramMap.put("zhjgld3",getCount("zhjgld3",zzMap));
            countMap2(zhjgAssessEdQhList4,zhjgld4count1,zhjgld4count2,zhjgld4count3,zhjgld4count4,zhjgld4count5,zzMap,"zhjgld4");
            paramMap.put("zhjgld4",getCount("zhjgld4",zzMap));
            countMap2(zhjgAssessEdQhList5,zhjgld5count1,zhjgld5count2,zhjgld5count3,zhjgld5count4,zhjgld5count5,zzMap,"zhjgld5");
            paramMap.put("zhjgld5",getCount("zhjgld5",zzMap));
            Map<String,Object> map1=new HashMap();
            map1.put("zhjgld1",zhjgAssessEdQhList1);
            map1.put("zhjgld2",zhjgAssessEdQhList2);
            map1.put("zhjgld3",zhjgAssessEdQhList3);
            map1.put("zhjgld4",zhjgAssessEdQhList4);
            map1.put("zhjgld5",zhjgAssessEdQhList5);
            for (int i = 0; i < yearSplit.length; i++) {
                policyMap.put("zhjgAssessEdQhList"+(i+1), rowTableRenderPolicy);
                paramMap.put("zhjgAssessEdQhList"+(i+1), map1.get("zhjgld"+(i+1)));
            }

//            policyMap.put("zhjgAssessEdQhList2", rowTableRenderPolicy);
//            paramMap.put("zhjgAssessEdQhList2", zhjgAssessEdQhList2);
//            policyMap.put("zhjgAssessEdQhList3", rowTableRenderPolicy);
//            paramMap.put("zhjgAssessEdQhList3", zhjgAssessEdQhList3);
//            policyMap.put("zhjgAssessEdQhList4", rowTableRenderPolicy);
//            paramMap.put("zhjgAssessEdQhList4", zhjgAssessEdQhList4);
//            policyMap.put("zhjgAssessEdQhList5", rowTableRenderPolicy);
//            paramMap.put("zhjgAssessEdQhList5", zhjgAssessEdQhList5);
        }
        Calendar calendar = Calendar.getInstance();
        paramMap.put("customTableList",new ArrayList<>());
        createWordReport1(policyMap, paramMap, inputNum,bgId);
        logger.info("word报告生产成功");

        return resultMap;
    }

    private Map<String,String> buildStructureArea(){
        Map<String,String> map = new HashMap<>(13);
        map.put("城镇其他结构房屋格网","0.00");
        map.put("农村木竹结构房屋格网","0.00");
        map.put("城镇钢混结构房屋格网","0.00");
        map.put("城镇钢结构房屋格网","0.00");
        map.put("农村混杂结构房屋格网","0.00");
        map.put("农村砌体结构房屋格网","0.00");
        map.put("农村钢混结构房屋格网","0.00");
        map.put("农村底部框架结构房屋格网","0.00");
        map.put("农村钢结构房屋格网","0.00");
        map.put("农村土木石木结构房屋格网","0.00");
        map.put("农村其他结构房屋格网","0.00");
        map.put("城镇砌体结构房屋格网","0.00");
        map.put("城镇木结构房屋格网","0.00");
        return map;
    }
    @Override
    public void buildCommonReportParam(Map<String, Object> paramMap, Map<String,RenderPolicy> policyMap, String taskId, Map<String,Object> taskObj, String inputNum,String flag) throws Exception{
        if(paramMap==null){
            paramMap = new HashMap<>();
        }
        if(policyMap==null){
            policyMap = new HashMap<>();
        }
        //获取任务关联的省市县
        List<PCC> pccs = pccRepository.queryToponym(taskId);
        String geom = publicOperateService.getDistrictGeom(taskObj);
        //图片合集
        getPictures(paramMap,taskId,flag);
        logger.info("buildCommonReportParam构建公共的数据属性 begin");
        Object house_data_flag_v = taskObj.get("house_data_flag");
        //0为单体1为网格
        String house_data_flag="0";
        if(house_data_flag_v!=null){
            house_data_flag=house_data_flag_v.toString();
        }

        //1.建筑物单体数据 /建筑物网格   ---各个结构类型的建筑面积
        List<ReportCommonData> dataList1 = new ArrayList<ReportCommonData>();
        //1.建筑物单体数据 /建筑物网格  --	各个设防情况下的建筑面积
        List<ReportCommonData> dataList2 = new ArrayList<ReportCommonData>();

        String buildingType="单体数据";
        String buildingTypeName="建筑物单体数据";
        paramMap.put("showGrid",true);
        if("0".equals(house_data_flag)){
            //1.建筑物单体数据
            dataList1 = getBuildingIndividualCal(taskId);
            //2.建筑物单体数据 2)	各个设防情况下的建筑面积
            dataList2 = getBuildingIndividualSfqkCal(taskId);
            paramMap.put("showGrid",false);
        }else{
            //1.房屋网格数据
            dataList1 = getGridDataCal(taskId);
            //2.房屋网格 2)	各个设防情况下的建筑面积
            dataList2 = getGridDataSfqkCal(taskId);

            buildingTypeName="建筑物格网数据";
            buildingType="建筑物格网";
        }
        if(dataList1.size()<13){
            Map<String, String> structureAreaMap = buildStructureArea();
            List<String> nameList = dataList1.stream().map(ReportCommonData::getDataName).collect(Collectors.toList());
            Iterator<String> iterator = structureAreaMap.keySet().iterator();
            while(iterator.hasNext()){
                String key = iterator.next();
                if(!nameList.contains(key)){
                    ReportCommonData reportCommonData = new ReportCommonData();
                    reportCommonData.setDataName(key);
                    reportCommonData.setDataValue(structureAreaMap.get(key));
                    dataList1.add(reportCommonData);
                }
            }
        }
        List<Map<String,Object>> resetPriceList = new ArrayList<>();
        if(PlatformObjectUtils.isNotEmpty(pccs) && pccs.size()>0){
            for (PCC pcc : pccs) {
                List<Map<String,Object>> list = getFxqhBuildingPriceTask(pcc);
                if(PlatformObjectUtils.isNotEmpty(list) && list.size()>0){
                    resetPriceList.addAll(list);
                }
            }
        }
        //List<Map<String,Object>> resetPriceList = getFxqhBuildingPriceTask(taskId);

        policyMap.put("dataList1",rowTableRenderPolicy);
        policyMap.put("dataList2",rowTableRenderPolicy);
        policyMap.put("resetPriceList",rowTableRenderPolicy);

        //任务名称
        String taskName = taskObj.get("assess_name")+"";
        //单位名称
        String deptName="XX单位A";
        //创建时间
        String createTime=new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        paramMap.put("name",taskName);
        paramMap.put("deptName",deptName);
        paramMap.put("createTime",createTime);
        paramMap.put("buildingTypeName",buildingTypeName);
        paramMap.put("buildingType",buildingType);

        paramMap.put("dataList1",dataList1);
        for (ReportCommonData reportCommonData : dataList2) {
            if("未设防".equals(reportCommonData.getDataName())){
                reportCommonData.setSort(0);
            }else{
                String value = reportCommonData.getDataName().replace("度", "");
                reportCommonData.setSort(Integer.parseInt(value));
            }
        }
        List<ReportCommonData> newDataList2 = dataList2.stream().sorted(Comparator.comparing(ReportCommonData::getSort)).collect(Collectors.toList());
        paramMap.put("dataList2",newDataList2);
        paramMap.put("resetPriceList",resetPriceList);


        //1.2人口数据/4.2地震人员受伤评估/4.3地震人员死亡评估 --当任务中评估对象选择了人员伤亡时显示此章节
        paramMap.put("assess_obj_flag_2",false);
        Object assess_obj = taskObj.get("assess_obj");
        if(!"1000000201".equals(inputNum)&&assess_obj!=null&&assess_obj.toString().contains("1")){//人员  概率不在此处处理
            paramMap.put("assess_obj_flag_2",true);
            //获取评估区域内人口总数
            Map<String,String> parMap = new HashMap<>();
            parMap.put("geom",geom);
            //parMap.put("dataVersion","JC02RKSJ20240222001");
            parMap.put("dataVersion",taskObj.get("popluation_version").toString());
            JcPopulationGridBo bo = jcsjRestManager.getJcPopulationGridGetByGeom(parMap);
            if(PlatformObjectUtils.isNotEmpty(bo.getData()) && bo.getCode()==200){
                paramMap.put("tzl3",new BigDecimal(bo.getData()).divide(new BigDecimal(10000),4,RoundingMode.HALF_DOWN));
            }else{
                paramMap.put("tzl3",0);
            }
            // 3.2.地震人员受伤评估
            policyMap.put("dzzhDzryqkTableList1",dzzhDzryqkCustomTableMethodPolicy);
            policyMap.put("dzzhDzryqkTableList2",dzzhDzryqkCustomTableMethodPolicy);
            String inputMode = "0";
            if("1000000102".equals(inputNum)){
                inputMode = "1";
            }else if("1000000103".equals(inputNum)){
                inputMode = "2";
            }
            List<Map<String,Object>> dzzhDzryqkTableList1 = pgldReportService.getFxqhCasualtiesCalculationEdForInjureDataList(taskId,inputMode);
            paramMap.put("dzzhDzryqkTableList1",dzzhDzryqkTableList1);
            // 3.3 地震人员死亡评估 表格策略
            List<Map<String,Object>> dzzhDzryqkTableList2 = pgldReportService.getFxqhCasualtiesCalculationEdForDeathDataList(taskId,inputMode);
            paramMap.put("dzzhDzryqkTableList2",dzzhDzryqkTableList2);
        }

        //1.3GDP数据 /4.4地震直接经济损失评估    --当任务中评估对象选择了经济损失时显示此章节
        paramMap.put("assess_obj_flag_1",false);
        if(!"1000000201".equals(inputNum)&&assess_obj!=null&&assess_obj.toString().contains("2")){//经济 概率不在此处处理
            paramMap.put("assess_obj_flag_1",true);
            //获取任务区域内的gdp
            JSONObject gdp = jcsjRestManager.getGdp(geom, taskObj.get("gdp_version").toString());
            if(PlatformObjectUtils.isNotEmpty(gdp.get("data"))){
                paramMap.put("GDP",new BigDecimal(gdp.get("data").toString()));
            }else {
                paramMap.put("GDP",BigDecimal.ZERO);
            }
            final BigDecimal[] previousGdp = {BigDecimal.ZERO};
            //获取上一年的gdp
            pccs.forEach(pcc ->{
                GdpVO gdpData = enterAssessQhRepository.getGdpByTaskIdAndDistrict(taskId,pcc.getPpName(),pcc.getCityName(),pcc.getName());
                if(gdpData != null ){
                    previousGdp[0] = previousGdp[0].add(gdpData.getPreviousGdp());
                }

            });
            paramMap.put("previousGdp", previousGdp[0]);
        }

        //控制显隐
        paramMap.put("assess_obj_flag_3",false);
        paramMap.put("assess_obj_flag_4",false);
        Object ld_pga = taskObj.get("ld_pga");
        Map<String, Object> stringObjectMap = this.getcountryBytaskId(taskId);
        String province = stringObjectMap.get("pp_name").toString();
        String city = stringObjectMap.get("city_name").toString();
        String county = stringObjectMap.get("name").toString();
        //pga
        if(ld_pga!=null&&ld_pga.toString().contains("1")&&"1000000201".equals(inputNum)){//04概率评估-发生概率 控制显隐
            JSONArray pgaOfYsx = jcsjRestManager.getPgaOfYsx(province, city, county);
            List<BasicLibraryVo> list = JSONObject.parseArray(JSONObject.toJSONString(pgaOfYsx), BasicLibraryVo.class);
            // 2.2易损性曲线
            //构建数据
//            BigDecimal sdmr = new BigDecimal(0.01);
//            BigDecimal mdmr = new BigDecimal(0.01);
//            BigDecimal edmr = new BigDecimal(0.01);
//            BigDecimal collapseMr = new BigDecimal(0.01);
//            BigDecimal sdBr = new BigDecimal(0.01);
//            BigDecimal mdBr = new BigDecimal(0.01);
//            BigDecimal edBr = new BigDecimal(0.01);
//            BigDecimal collapseBr = new BigDecimal(0.01);
            BigDecimal sdVal = new BigDecimal(0.01);
            BigDecimal mdVal = new BigDecimal(0.01);
            BigDecimal edVal = new BigDecimal(0.01);
            BigDecimal collapseVal = new BigDecimal(0.01);
            if(PlatformObjectUtils.isNotEmpty(list) && list.size()>0) {
//                BasicLibraryVo basicLibraryVo1 = list.get(0);
//                List<CurveVo> valueList = basicLibraryVo1.getValueList();
//                for (CurveVo stateValue : valueList) {
//                    switch (stateValue.getBreakState()) {
//                        case "轻微破坏":
//                            sdVal = stateValue.getFim();
//                            break;
//                        case "中等破坏":
//                            mdVal = stateValue.getFim();
//                            break;
//                        case "严重破坏":
//                            edVal = stateValue.getFim();
//                            break;
//                        case "倒塌":
//                            collapseVal = stateValue.getFim();
//                            break;
//                    }
//                }
//                List<BasicLibraryVo.stateValue> valueList = basicLibraryVo1.getValueList();
//                for (BasicLibraryVo.stateValue stateValue : valueList) {
//                    switch (stateValue.getDestructiveState()) {
//                        case "轻微破坏":
//                            sdmr = stateValue.getMr();
//                            sdBr = stateValue.getBr();
//                            break;
//                        case "中等破坏":
//                            mdmr = stateValue.getMr();
//                            mdBr = stateValue.getBr();
//                            break;
//                        case "严重破坏":
//                            edmr = stateValue.getMr();
//                            edBr = stateValue.getBr();
//                            break;
//                        case "倒塌":
//                            collapseMr = stateValue.getMr();
//                            collapseBr = stateValue.getBr();
//                            break;
//                    }
//                }
//                Map<String, List<Object>> stringListMap = fImCountUtils.fImCount(sdmr, mdmr, edmr, collapseMr, sdBr, mdBr, edBr, collapseBr);
                Map<String, List<Object>> stringListMap = fImCountUtils.fImCount(sdVal, mdVal, edVal, collapseVal);
                List<Object> sd = stringListMap.get("SD");
                List<Object> md = stringListMap.get("MD");
                List<Object> ed = stringListMap.get("ED");
                List<Object> cd = stringListMap.get("CD");
                List<Object> xx = stringListMap.get("xx");

                //折线图生成
                ChartMultiSeriesRenderData line = new ChartMultiSeriesRenderData();
                line.setChartTitle("易损性曲线");
                //参数为数组
                line.setCategories(xx.toArray(new String[xx.size()]));
                List<SeriesRenderData> seriesRenderDatas1 = new ArrayList<SeriesRenderData>();
                seriesRenderDatas1.add(new SeriesRenderData("轻微", sd.toArray(new Double[sd.size()])));
                seriesRenderDatas1.add(new SeriesRenderData("中等", md.toArray(new Double[md.size()])));
                seriesRenderDatas1.add(new SeriesRenderData("严重", ed.toArray(new Double[ed.size()])));
                seriesRenderDatas1.add(new SeriesRenderData("倒塌", cd.toArray(new Double[cd.size()])));
                line.setSeriesDatas(seriesRenderDatas1);
                paramMap.put("combChart", line);
                paramMap.put("assess_obj_flag_4", true);
            }
        }else{
            //2 建筑物地震易损性 查询数据集合  烈度
            policyMap.put("customTableList",customTableMethodPolicy);
            List<ReportYsxVO> reportYsxDataList = getReportYsxDataList(taskId);
            List<Map<String,Object>> reportYsxes = buildReportYsxData(reportYsxDataList);
            //List<Map<String,Object>> customTableList=getBuildingJzwysxDataList(taskId);
            paramMap.put("customTableList",reportYsxes);
            if(ld_pga!=null&&ld_pga.toString().contains("0")&&"1000000201".equals(inputNum)){//04概率评估-发生概率 控制显隐
                paramMap.put("assess_obj_flag_3",true);
            }
        }
        buildTableData(paramMap, taskObj, stringObjectMap);
        Object seismic_input_mode = taskObj.get("seismic_input_mode");
        paramMap.put("assess_obj_flag_5",false);//任务中选的是超越概率时显示
        if(seismic_input_mode!=null&&seismic_input_mode.toString().contains("4")&&"1000000201".equals(inputNum)){//04概率评估-发生概率 控制显隐
            paramMap.put("assess_obj_flag_5",true);
        }



        //结构类型面积柱状图
        String []categories=null;
        Double []seriesValue=null;

        String []categories2=null;
        Double []seriesValue2=null;
        if("0".equals(house_data_flag)){
            categories=new String[]{"钢结构","钢筋混凝土结构-剪力墙结构","钢筋混凝土结构-框架结构","钢筋混凝土结构-框架-剪力墙结构"};
            seriesValue = new Double[]{0D,0D,0D,0D};

            categories2 =new String[]{"未设防","6度","7度","8度","9度"};
            seriesValue2=new Double[]{0D,0D,0D,0D,0D};
        }else{
            categories=new String[]{"城镇钢混结构房屋格网","城镇钢结构房屋格网","城镇木结构房屋格网"};
            seriesValue = new Double[]{0D,0D,0D};

                categories2 =new String[]{"未设防","6度","7度","8度","9度"};
            seriesValue2=new Double[]{0D,0D,0D,0D,0D};
        }

        if(!dataList1.isEmpty()){
            categories=new String[dataList1.size()];
            seriesValue=new Double[dataList1.size()];
            for(int i=0;i<dataList1.size();i++){
                ReportCommonData data = dataList1.get(i);
                categories[i]=data.getDataName();
                try{
                    seriesValue[i]=Double.valueOf(PlatformObjectUtils.isNotEmpty(data.getDataValue())?data.getDataValue():"0");
                }catch (NullPointerException e){
                    e.printStackTrace();
                }

            }
        }

        ChartMultiSeriesRenderData barChart1 = Charts
                .ofMultiSeries(null, categories)
                .addSeries("", seriesValue)
                .create();
        paramMap.put("barChart1",barChart1);

        //设防情况下的建筑面积柱状图

        if(!newDataList2.isEmpty()) {
            categories2 = new String[newDataList2.size()];
            seriesValue2 = new Double[newDataList2.size()];
            for (int i = 0; i < newDataList2.size(); i++) {
                ReportCommonData data = newDataList2.get(i);
                categories2[i] = data.getDataName();
                seriesValue2[i] = Double.valueOf(data.getDataValue());
            }
        }
        ChartMultiSeriesRenderData barChart2 = Charts
                .ofMultiSeries(null, categories2)
                .addSeries("", seriesValue2)
                .create();
        paramMap.put("barChart2",barChart2);

        //4地震灾害风险区划-4.1.1区划方法
        List<Map<String, Object>> qhmapsList = selectByTypeList("1","4","5");
        for (Map<String, Object> map : qhmapsList) {
            switch (map.get("type").toString()){
                case "1": map.put("type","结构破坏");break;
                case "4": map.put("type","经济损失");break;
                case "5": map.put("type","经济损失（新疆、青海和西藏地区）");break;
            }
        }
        List<Map<String, Object>> personmapsList = selectPersonByTypeList("2","3");
        for (Map<String, Object> map : personmapsList) {
            switch (map.get("type").toString()){
                case "2": map.put("type","人员死亡");break;
                case "3": map.put("type","人员死亡（新疆、青海和西藏地区）");break;
            }
        }
        qhmapsList.addAll(personmapsList);
        policyMap.put("qhmapsList", rowTableRenderPolicy);
        paramMap.put("qhmapsList", qhmapsList);
        //4.2综合风险区划
        paramMap.put("assess_obj_flag_6",false);
        if(assess_obj!=null&&assess_obj.toString().contains("1")&&assess_obj.toString().contains("2")&&assess_obj.toString().contains("0")){//如果3个都存在的话 则展示综合风险区划
            paramMap.put("assess_obj_flag_6",true);
            //4.2综合风险区划--4.2.1区划方法
            List<Map<String, Object>> zhqhmapsList = selectzhByTypeList("1","4","5");
            for (Map<String, Object> map : zhqhmapsList) {
                switch (map.get("type").toString()){
                    case "1": map.put("type","结构破坏");break;
                    case "4": map.put("type","经济损失");break;
                    case "5": map.put("type","经济损失（新疆、青海和西藏地区）");break;
                }
            }
            List<Map<String, Object>> personZhqhmapsList = selectPersonZhByTypeList("2","3");
            for (Map<String, Object> map : personZhqhmapsList) {
                switch (map.get("type").toString()){
                    case "2": map.put("type","人员死亡");break;
                    case "3": map.put("type","人员死亡（新疆、青海和西藏地区）");break;
                }
            }
            if(PlatformObjectUtils.isNotEmpty(personZhqhmapsList)){
                zhqhmapsList.addAll(personZhqhmapsList);
            }
            policyMap.put("zhqhmapsList", rowTableRenderPolicy);
            paramMap.put("zhqhmapsList", zhqhmapsList);
        }

        //4地震灾害风险区划-4.1.2.1结构破坏  开始
        FxqhAssessEdQhResult param= new FxqhAssessEdQhResult();
        param.setEstimateObj("0");
        param.setTaskId(taskId);
//        param.setTaskId("fa09c740ed744827903490ee750ce092");
        String type="1";
        if("1000000201".equals(inputNum)){//概率时跳出不做后续赋值
            logger.info("buildCommonReportParam构建公共的数据属性 end");
            return;
        }

        if("1000000102".equals(inputNum)){
            type="2";
        }else if("1000000103".equals(inputNum)){//地震场
            type="3";
            String influenceVersion = taskObj.get("influence_field_version").toString();
            param.setCondition(influenceVersion);
//            param.setTaskId("8c4d6c0c49584dc1817001ca0af690b5");
//            param.setCondition("20231024YXC001");
        }
        List<FxqhAssessEdQhResultVo> jgAssessEdQhList1=new ArrayList<>();
        List<FxqhAssessEdQhResultVo> jgAssessEdQhList2=new ArrayList<>();
        List<FxqhAssessEdQhResultVo> jgAssessEdQhList3=new ArrayList<>();
        List<FxqhAssessEdQhResultVo> jgAssessEdQhList4=new ArrayList<>();
        List<FxqhAssessEdQhResultVo> jgAssessEdQhList5=new ArrayList<>();
        int jgld1count1=0,jgld1count2=0,jgld1count3=0,jgld1count4=0,jgld1count5=0;
        int jgld2count1=0,jgld2count2=0,jgld2count3=0,jgld2count4=0,jgld2count5=0;
        int jgld3count1=0,jgld3count2=0,jgld3count3=0,jgld3count4=0,jgld3count5=0;
        int jgld4count1=0,jgld4count2=0,jgld4count3=0,jgld4count4=0,jgld4count5=0;
        int jgld5count1=0,jgld5count2=0,jgld5count3=0,jgld5count4=0,jgld5count5=0;
        List<FxqhAssessEdQhResultVo> jgAssessEdQhList = enterAssessQhService.getAssessEdQhList(param, null, null);
        //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
        StringBuilder jjphsb = new StringBuilder("风险等级");
        Map<String,Integer> jgMap = new HashMap<>();
        insertList(jgAssessEdQhList,jgAssessEdQhList1,jgAssessEdQhList2,jgAssessEdQhList3,jgAssessEdQhList4,jgAssessEdQhList5,type);
        countMap(jgAssessEdQhList1,jgld1count1,jgld1count2,jgld1count3,jgld1count4,jgld1count5,jgMap,"jgld1");
        Integer jgld1count11 = jgMap.get("jgld1count1");
        if(jgld1count11>0){
            jjphsb.append("I级区县").append(jgld1count11).append("个,");
        }
        Integer jgld1count12 = jgMap.get("jgld1count2");
        if(jgld1count12>0){
            jjphsb.append("II级区县").append(jgld1count12).append("个,");
        }
        Integer jgld1count13 = jgMap.get("jgld1count3");
        if(jgld1count13>0){
            jjphsb.append("III级区县").append(jgld1count13).append("个,");
        }
        Integer jgld1count14 = jgMap.get("jgld1count4");
        if(jgld1count14>0){
            jjphsb.append("IV级区县").append(jgld1count14).append("个,");
        }
        Integer jgld1count15 = jgMap.get("jgld1count5");
        if(jgld1count15>0){
            jjphsb.append("V级区县").append(jgld1count15).append("个,");
        }
        String jjph = jjphsb.toString();
        if(jjph.endsWith(",")){
            jjph = jjph.substring(0,jjph.lastIndexOf(","));
        }
        paramMap.put("jjph1",jjph);
        jjphsb = new StringBuilder("风险等级");
        jgMap = new HashMap<>();
        countMap(jgAssessEdQhList2,jgld2count1,jgld2count2,jgld2count3,jgld2count4,jgld2count5,jgMap,"jgld2");
        Integer jgld1count21 = jgMap.get("jgld2count1");
        if(jgld1count21>0){
            jjphsb.append("I级区县").append(jgld1count21).append("个,");
        }
        Integer jgld1count22 = jgMap.get("jgld2count2");
        if(jgld1count22>0){
            jjphsb.append("II级区县").append(jgld1count22).append("个,");
        }
        Integer jgld1count23 = jgMap.get("jgld2count3");
        if(jgld1count23>0){
            jjphsb.append("III级区县").append(jgld1count23).append("个,");
        }
        Integer jgld1count24 = jgMap.get("jgld2count4");
        if(jgld1count24>0){
            jjphsb.append("IV级区县").append(jgld1count24).append("个,");
        }
        Integer jgld1count25 = jgMap.get("jgld2count5");
        if(jgld1count25>0){
            jjphsb.append("V级区县").append(jgld1count25).append("个,");
        }
        jjph = jjphsb.toString();
        if(jjph.endsWith(",")){
            jjph = jjph.substring(0,jjph.lastIndexOf(","));
        }
        paramMap.put("jjph2",jjph);
        jjphsb = new StringBuilder("风险等级");
        jgMap = new HashMap<>();
        countMap(jgAssessEdQhList3,jgld3count1,jgld3count2,jgld3count3,jgld3count4,jgld3count5,jgMap,"jgld3");
        Integer jgld1count31 = jgMap.get("jgld3count1");
        if(jgld1count31>0){
            jjphsb.append("I级区县").append(jgld1count31).append("个,");
        }
        Integer jgld1count32 = jgMap.get("jgld3count2");
        if(jgld1count32>0){
            jjphsb.append("II级区县").append(jgld1count32).append("个,");
        }
        Integer jgld1count33 = jgMap.get("jgld3count3");
        if(jgld1count33>0){
            jjphsb.append("III级区县").append(jgld1count33).append("个,");
        }
        Integer jgld1count34 = jgMap.get("jgld3count4");
        if(jgld1count34>0){
            jjphsb.append("IV级区县").append(jgld1count34).append("个,");
        }
        Integer jgld1count35 = jgMap.get("jgld3count5");
        if(jgld1count35>0){
            jjphsb.append("V级区县").append(jgld1count35).append("个,");
        }
        jjph = jjphsb.toString();
        if(jjph.endsWith(",")){
            jjph = jjph.substring(0,jjph.lastIndexOf(","));
        }
        paramMap.put("jjph3",jjph);
        jjphsb = new StringBuilder("风险等级");
        jgMap = new HashMap<>();
        countMap(jgAssessEdQhList4,jgld4count1,jgld4count2,jgld4count3,jgld4count4,jgld4count5,jgMap,"jgld4");
        Integer jgld1count41 = jgMap.get("jgld4count1");
        if(jgld1count41>0){
            jjphsb.append("I级区县").append(jgld1count41).append("个,");
        }
        Integer jgld1count42 = jgMap.get("jgld4count2");
        if(jgld1count42>0){
            jjphsb.append("II级区县").append(jgld1count42).append("个,");
        }
        Integer jgld1count43 = jgMap.get("jgld4count3");
        if(jgld1count43>0){
            jjphsb.append("III级区县").append(jgld1count43).append("个,");
        }
        Integer jgld1count44 = jgMap.get("jgld4count4");
        if(jgld1count44>0){
            jjphsb.append("IV级区县").append(jgld1count44).append("个,");
        }
        Integer jgld1count45 = jgMap.get("jgld4count5");
        if(jgld1count45>0){
            jjphsb.append("V级区县").append(jgld1count45).append("个,");
        }
        jjph = jjphsb.toString();
        if(jjph.endsWith(",")){
            jjph = jjph.substring(0,jjph.lastIndexOf(","));
        }
        paramMap.put("jjph4",jjph);
        jjphsb = new StringBuilder("风险等级");
        jgMap = new HashMap<>();
        countMap(jgAssessEdQhList5,jgld5count1,jgld5count2,jgld5count3,jgld5count4,jgld5count5,jgMap,"jgld5");
        Integer jgld1count51 = jgMap.get("jgld5count1");
        if(jgld1count51>0){
            jjphsb.append("I级区县").append(jgld1count51).append("个,");
        }
        Integer jgld1count52 = jgMap.get("jgld5count2");
        if(jgld1count52>0){
            jjphsb.append("II级区县").append(jgld1count52).append("个,");
        }
        Integer jgld1count53 = jgMap.get("jgld5count3");
        if(jgld1count53>0){
            jjphsb.append("III级区县").append(jgld1count53).append("个,");
        }
        Integer jgld1count54 = jgMap.get("jgld5count4");
        if(jgld1count54>0){
            jjphsb.append("IV级区县").append(jgld1count54).append("个,");
        }
        Integer jgld1count55 = jgMap.get("jgld5count5");
        if(jgld1count55>0){
            jjphsb.append("V级区县").append(jgld1count55).append("个,");
        }
        jjph = jjphsb.toString();
        if(jjph.endsWith(",")){
            jjph = jjph.substring(0,jjph.lastIndexOf(","));
        }
        paramMap.put("jjph5",jjph);
        policyMap.put("jgAssessEdQhList1", rowTableRenderPolicy);
        paramMap.put("jgAssessEdQhList1", jgAssessEdQhList1);
        policyMap.put("jgAssessEdQhList2", rowTableRenderPolicy);
        paramMap.put("jgAssessEdQhList2", jgAssessEdQhList2);
        policyMap.put("jgAssessEdQhList3", rowTableRenderPolicy);
        paramMap.put("jgAssessEdQhList3", jgAssessEdQhList3);
        policyMap.put("jgAssessEdQhList4", rowTableRenderPolicy);
        paramMap.put("jgAssessEdQhList4", jgAssessEdQhList4);
        policyMap.put("jgAssessEdQhList5", rowTableRenderPolicy);
        paramMap.put("jgAssessEdQhList5", jgAssessEdQhList5);

        Map<String,Integer> ryswMap = new HashMap<>();
        //4.1.2.2人员死亡
        if(assess_obj!=null&&assess_obj.toString().contains("1")) {//人员
            param.setEstimateObj("1");
            List<FxqhAssessEdQhResultVo> swAssessEdQhList1 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> swAssessEdQhList2 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> swAssessEdQhList3 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> swAssessEdQhList4 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> swAssessEdQhList5 = new ArrayList<>();
            int swld1count1 = 0, swld1count2 = 0, swld1count3 = 0, swld1count4 = 0, swld1count5 = 0;
            int swld2count1 = 0, swld2count2 = 0, swld2count3 = 0, swld2count4 = 0, swld2count5 = 0;
            int swld3count1 = 0, swld3count2 = 0, swld3count3 = 0, swld3count4 = 0, swld3count5 = 0;
            int swld4count1 = 0, swld4count2 = 0, swld4count3 = 0, swld4count4 = 0, swld4count5 = 0;
            int swld5count1 = 0, swld5count2 = 0, swld5count3 = 0, swld5count4 = 0, swld5count5 = 0;
            List<FxqhAssessEdQhResultVo> swAssessEdQhList = enterAssessQhService.getAssessEdQhList(param, null, null);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList(swAssessEdQhList, swAssessEdQhList1, swAssessEdQhList2, swAssessEdQhList3, swAssessEdQhList4, swAssessEdQhList5,type);
            countMap(swAssessEdQhList1, swld1count1, swld1count2, swld1count3, swld1count4, swld1count5, ryswMap, "swld1");
            String swld1 = getCount("swld1", ryswMap);
            paramMap.put("swld1",swld1);
            countMap(swAssessEdQhList2, swld2count1, swld2count2, swld2count3, swld2count4, swld2count5, ryswMap, "swld2");
            paramMap.put("swld2",getCount("swld2", ryswMap));
            countMap(swAssessEdQhList3, swld3count1, swld3count2, swld3count3, swld3count4, swld3count5, ryswMap, "swld3");
            paramMap.put("swld3",getCount("swld3", ryswMap));
            countMap(swAssessEdQhList4, swld4count1, swld4count2, swld4count3, swld4count4, swld4count5, ryswMap, "swld4");
            paramMap.put("swld4",getCount("swld4", ryswMap));
            countMap(swAssessEdQhList5, swld5count1, swld5count2, swld5count3, swld5count4, swld5count5, ryswMap, "swld5");
            paramMap.put("swld5",getCount("swld5", ryswMap));
            policyMap.put("swAssessEdQhList1", rowTableRenderPolicy);
            paramMap.put("swAssessEdQhList1", swAssessEdQhList1);
            policyMap.put("swAssessEdQhList2", rowTableRenderPolicy);
            paramMap.put("swAssessEdQhList2", swAssessEdQhList2);
            policyMap.put("swAssessEdQhList3", rowTableRenderPolicy);
            paramMap.put("swAssessEdQhList3", swAssessEdQhList3);
            policyMap.put("swAssessEdQhList4", rowTableRenderPolicy);
            paramMap.put("swAssessEdQhList4", swAssessEdQhList4);
            policyMap.put("swAssessEdQhList5", rowTableRenderPolicy);
            paramMap.put("swAssessEdQhList5", swAssessEdQhList5);
        }
        //4.1.2.3经济损失
        Map<String,Integer> jjssMap = new HashMap<>();
        if(assess_obj!=null&&assess_obj.toString().contains("2")) {//经济
            param.setEstimateObj("2");
            List<FxqhAssessEdQhResultVo> jjAssessEdQhList1 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> jjAssessEdQhList2 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> jjAssessEdQhList3 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> jjAssessEdQhList4 = new ArrayList<>();
            List<FxqhAssessEdQhResultVo> jjAssessEdQhList5 = new ArrayList<>();
            int jjld1count1 = 0, jjld1count2 = 0, jjld1count3 = 0, jjld1count4 = 0, jjld1count5 = 0;
            int jjld2count1 = 0, jjld2count2 = 0, jjld2count3 = 0, jjld2count4 = 0, jjld2count5 = 0;
            int jjld3count1 = 0, jjld3count2 = 0, jjld3count3 = 0, jjld3count4 = 0, jjld3count5 = 0;
            int jjld4count1 = 0, jjld4count2 = 0, jjld4count3 = 0, jjld4count4 = 0, jjld4count5 = 0;
            int jjld5count1 = 0, jjld5count2 = 0, jjld5count3 = 0, jjld5count4 = 0, jjld5count5 = 0;
            List<FxqhAssessEdQhResultVo> jjAssessEdQhList = enterAssessQhService.getAssessEdQhList(param, null, null);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList(jjAssessEdQhList, jjAssessEdQhList1, jjAssessEdQhList2, jjAssessEdQhList3, jjAssessEdQhList4, jjAssessEdQhList5,type);
            countMap(jjAssessEdQhList1, jjld1count1, jjld1count2, jjld1count3, jjld1count4, jjld1count5, jjssMap, "jjld1");
            paramMap.put("jjld1",getCount("jjld1", jjssMap));
            countMap(jjAssessEdQhList2, jjld2count1, jjld2count2, jjld2count3, jjld2count4, jjld1count5, jjssMap, "jjld2");
            paramMap.put("jjld2",getCount("jjld2", jjssMap));
            countMap(jjAssessEdQhList3, jjld3count1, jjld3count2, jjld3count3, jjld3count4, jjld3count5, jjssMap, "jjld3");
            paramMap.put("jjld3",getCount("jjld3", jjssMap));
            countMap(jjAssessEdQhList4, jjld4count1, jjld4count2, jjld4count3, jjld4count4, jjld4count5, jjssMap, "jjld4");
            paramMap.put("jjld4",getCount("jjld4", jjssMap));
            countMap(jjAssessEdQhList5, jjld5count1, jjld5count2, jjld5count3, jjld5count4, jjld5count5, jjssMap, "jjld5");
            paramMap.put("jjld5",getCount("jjld5", jjssMap));
            policyMap.put("jjAssessEdQhList1", rowTableRenderPolicy);
            paramMap.put("jjAssessEdQhList1", jjAssessEdQhList1);
            policyMap.put("jjAssessEdQhList2", rowTableRenderPolicy);
            paramMap.put("jjAssessEdQhList2", jjAssessEdQhList2);
            policyMap.put("jjAssessEdQhList3", rowTableRenderPolicy);
            paramMap.put("jjAssessEdQhList3", jjAssessEdQhList3);
            policyMap.put("jjAssessEdQhList4", rowTableRenderPolicy);
            paramMap.put("jjAssessEdQhList4", jjAssessEdQhList4);
            policyMap.put("jjAssessEdQhList5", rowTableRenderPolicy);
            paramMap.put("jjAssessEdQhList5", jjAssessEdQhList5);
        }
        Map<String,Integer> zzMap = new HashMap<>();
        if(assess_obj!=null&&assess_obj.toString().contains("1")&&assess_obj.toString().contains("2")&&assess_obj.toString().contains("0")) {//如果3个都存在的话 则展示综合风险区划
            //4.2综合风险区划--4.2.2风险区划等级
            QueryParam queryParam=new QueryParam();
            queryParam.setId(taskId);
            queryParam.setCategory(Integer.parseInt(flag)-1+"");
//            String queryParamType="0";
//            queryParam.setCategory("1");
//            if("1000000102".equals(inputNum)){//概率
//                queryParamType="1";
//                queryParam.setCategory("2");
//            }else if("1000000103".equals(inputNum)){//地震场
//                queryParamType="2";
//                //sString influenceVersion = taskObj.get("influence_field_version").toString();
//                //queryParam.setType(influenceVersion);
//                queryParam.setCategory("2");
////            param.setTaskId("8c4d6c0c49584dc1817001ca0af690b5");
////            param.setCondition("20231024YXC001");
//            }else if("100000201".equals(inputNum)){// 概率评估发生概率
//                queryParamType="3";
//            }
            List<PopulationAndLoss> zhjgAssessEdQhList1=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList2=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList3=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList4=new ArrayList<>();
            List<PopulationAndLoss> zhjgAssessEdQhList5=new ArrayList<>();
            int zhjgld1count1=0,zhjgld1count2=0,zhjgld1count3=0,zhjgld1count4=0,zhjgld1count5=0;
            int zhjgld2count1=0,zhjgld2count2=0,zhjgld2count3=0,zhjgld2count4=0,zhjgld2count5=0;
            int zhjgld3count1=0,zhjgld3count2=0,zhjgld3count3=0,zhjgld3count4=0,zhjgld3count5=0;
            int zhjgld4count1=0,zhjgld4count2=0,zhjgld4count3=0,zhjgld4count4=0,zhjgld4count5=0;
            int zhjgld5count1=0,zhjgld5count2=0,zhjgld5count3=0,zhjgld5count4=0,zhjgld5count5=0;
            List<PopulationAndLoss> zhjgAssessEdQhList = this.getzhjgResult(queryParam);
            //Ⅵ，Ⅶ，Ⅷ，Ⅸ，Ⅹ
            insertList2(zhjgAssessEdQhList,zhjgAssessEdQhList1,zhjgAssessEdQhList2,zhjgAssessEdQhList3,zhjgAssessEdQhList4,zhjgAssessEdQhList5);
            countMap2(zhjgAssessEdQhList1,zhjgld1count1,zhjgld1count2,zhjgld1count3,zhjgld1count4,zhjgld1count5,zzMap,"zhjgld1");
            paramMap.put("zhjgld1", getCount("zhjgld1",zzMap));
            countMap2(zhjgAssessEdQhList2,zhjgld2count1,zhjgld2count2,zhjgld2count3,zhjgld2count4,zhjgld2count5,zzMap,"zhjgld2");
            paramMap.put("zhjgld2", getCount("zhjgld2",zzMap));
            countMap2(zhjgAssessEdQhList3,zhjgld3count1,zhjgld3count2,zhjgld3count3,zhjgld3count4,zhjgld3count5,zzMap,"zhjgld3");
            paramMap.put("zhjgld3", getCount("zhjgld3",zzMap));
            countMap2(zhjgAssessEdQhList4,zhjgld4count1,zhjgld4count2,zhjgld4count3,zhjgld4count4,zhjgld4count5,zzMap,"zhjgld4");
            paramMap.put("zhjgld4", getCount("zhjgld4",zzMap));
            countMap2(zhjgAssessEdQhList5,zhjgld5count1,zhjgld5count2,zhjgld5count3,zhjgld5count4,zhjgld5count5,zzMap,"zhjgld5");
            paramMap.put("zhjgld5", getCount("zhjgld5",zzMap));
            policyMap.put("zhjgAssessEdQhList1", rowTableRenderPolicy);
            paramMap.put("zhjgAssessEdQhList1", zhjgAssessEdQhList1);
            policyMap.put("zhjgAssessEdQhList2", rowTableRenderPolicy);
            paramMap.put("zhjgAssessEdQhList2", zhjgAssessEdQhList2);
            policyMap.put("zhjgAssessEdQhList3", rowTableRenderPolicy);
            paramMap.put("zhjgAssessEdQhList3", zhjgAssessEdQhList3);
            policyMap.put("zhjgAssessEdQhList4", rowTableRenderPolicy);
            paramMap.put("zhjgAssessEdQhList4", zhjgAssessEdQhList4);
            policyMap.put("zhjgAssessEdQhList5", rowTableRenderPolicy);
            paramMap.put("zhjgAssessEdQhList5", zhjgAssessEdQhList5);
        }
        logger.info("buildCommonReportParam构建公共的数据属性 end");

    }

    private String getCount(String type,Map<String,Integer> map){
        StringBuilder jjphsb = new StringBuilder("风险等级");
        Integer jgld1count51 = map.get(type+"count1");
        if(jgld1count51>0){
            jjphsb.append("I级区县").append(jgld1count51).append("个,");
        }
        Integer jgld1count52 = map.get(type+"count2");
        if(jgld1count52>0){
            jjphsb.append("II级区县").append(jgld1count52).append("个,");
        }
        Integer jgld1count53 = map.get(type+"count3");
        if(jgld1count53>0){
            jjphsb.append("III级区县").append(jgld1count53).append("个,");
        }
        Integer jgld1count54 = map.get(type+"count4");
        if(jgld1count54>0){
            jjphsb.append("IV级区县").append(jgld1count54).append("个,");
        }
        Integer jgld1count55 = map.get(type+"count5");
        if(jgld1count55>0){
            jjphsb.append("V级区县").append(jgld1count55).append("个,");
        }
        String countStr = jjphsb.toString();
        if(countStr.endsWith(",")){
            countStr = countStr.substring(0,countStr.lastIndexOf(","));
        }
        return countStr;
    }
    private List<Map<String, Object>> selectPersonZhByTypeList(String type1, String type2) {
        StringBuilder sb = new StringBuilder();
        sb.append("select type,'<='||cast(v1 as FLOAT) as v1,'('||cast(v1 as FLOAT)||','||cast(v2 as FLOAT)||']' as v2,'('||cast(v2 as FLOAT)||','||cast(v3 as FLOAT)||']' as v3,'('||cast(v3 as FLOAT)||','||cast(v4 as FLOAT)||']' as v4,'>='||cast(v4 as FLOAT) as v5 \n" +
                "from fxqh_comprehensive_risk_zone_set where type in ('"+type1+"','"+type2+"') order by type");
        String sql = sb.toString();
        logger.info("selectzhByTypeList方法查询的SQL:{},参数:{}",sb.toString());
        List<Map<String,Object>> dataList = jdbcTemplate.queryForList(sql);
        return dataList;
    }

    private List<Map<String, Object>> selectPersonByTypeList(String type1, String type2) {
        StringBuilder sb = new StringBuilder();
        sb.append("select type,'<='||cast(v1 as FLOAT) as v1,'('||cast(v1 as FLOAT)||','||cast(v2 as FLOAT)||']' as v2,'('||cast(v2 as FLOAT)||','||cast(v3 as FLOAT)||']' as v3,'('||cast(v3 as FLOAT)||','||cast(v4 as FLOAT)||']' as v4,'>='||cast(v4 as FLOAT) as v5 \n" +
                "from fxqh_single_indicator_risk_zone_set where type in ('"+type1+"','"+type2+"') order by type");
        String sql = sb.toString();
        logger.info("selectByTypeList方法查询的SQL:{},参数:{}",sb.toString());
        List<Map<String,Object>> dataList = jdbcTemplate.queryForList(sql);
        return dataList;
    }

    private void buildTableData(Map<String, Object> paramMap, Map<String, Object> taskObj, Map<String, Object> stringObjectMap) {
        //危险性分析
        String ldPga = (String)taskObj.get("ld_pga");
        String type = "0".equals(ldPga) ? "1":"0";
        //地震输入方式   3为发生概率危险性,4为超越概率危险性   当为4时需要将超越概率转化成发生概率
        String inputMode = (String)taskObj.get("seismic_input_mode");
//        //区县id
//        String cid = stringObjectMap.get("id").toString();
//        //区县code
//        String countyCode = sysAreaService.getDivisionCodeById(cid);
//        countyCode = JSONObject.parse(countyCode).toString();
        //role 0国家级管理员  1省级管理员  2市级管理员  3县级管理员   根据role决定查哪些表
        String role = taskObj.get("role").toString();
        //省级存省id,市级存市id,县级存县id,国家级存1  根据level决定查指定表中哪些数据
        String userLevelrole = taskObj.get("create_user_level").toString();
        //不同的级别差不同的表
        List<ReportAnalysis> reportAnalysisList = getReportAnalysis(type,role,userLevelrole);
        if(PlatformObjectUtils.isNotEmpty(reportAnalysisList) && reportAnalysisList.size()>0){
            TableRenderData tableRenderData = new TableRenderData();
           // Map<String, List<ReportAnalysis>> collect = reportAnalysisList.stream().collect(Collectors.groupingBy(ReportAnalysis::getKilometerGridId));
            Map<String, List<ReportAnalysis>> collect = reportAnalysisList.stream().collect(Collectors.groupingBy(ReportAnalysis::getId));
            AtomicInteger count = new AtomicInteger(0);
            Iterator<Map.Entry<String, List<ReportAnalysis>>> iterator = collect.entrySet().iterator();
            List<String> xxList = new ArrayList<>();
            Map<String,List<BigDecimal>> map = new HashMap<>();
            while(iterator.hasNext()){
                List<BigDecimal> countList = new ArrayList<>();
                List<ReportAnalysis> v = iterator.next().getValue();
                count.getAndAdd(1);
                if(count.get()>5){
                    break;
                }
                if(count.get()==1){
//                    RowRenderData rowRenderData = new RowRenderData();
//                    ParagraphRenderData graph1 = new ParagraphRenderData();
//                    graph1.addText("公里网格Id");
//                    CellRenderData cell = new CellRenderData();
//                    cell.addParagraph(graph1);
//                    rowRenderData.addCell(cell);
//                    graph1 = new ParagraphRenderData();
//                    graph1.addText("经度");
//                    cell = new CellRenderData();
//                    cell.addParagraph(graph1);
//                    rowRenderData.addCell(cell);
//                    graph1 = new ParagraphRenderData();
//                    graph1.addText("纬度");
//                    cell = new CellRenderData();
//                    cell.addParagraph(graph1);
//                    rowRenderData.addCell(cell);
//                    for(int i=0;i<v.size();i++){
//                        ParagraphRenderData newPara = new ParagraphRenderData();
//                        newPara.addText("IM（烈度）/发生概率");
//                        CellRenderData newCell = new CellRenderData();
//                        newCell.addParagraph(newPara);
//                        rowRenderData.addCell(newCell);
//                    }
//                    tableRenderData.addRow(rowRenderData);
                    RowRenderData rowRenderData = new RowRenderData();
                    List<String> imValues = v.stream().map(ReportAnalysis::getImValue).collect(Collectors.toList());
                    ParagraphRenderData graph1 = new ParagraphRenderData();
                    graph1.addText("公里网格Id");
                    CellRenderData cell = new CellRenderData();
                    cell.addParagraph(graph1);
                    rowRenderData.addCell(cell);
                    graph1 = new ParagraphRenderData();
                    graph1.addText("经度");
                    cell = new CellRenderData();
                    cell.addParagraph(graph1);
                    rowRenderData.addCell(cell);
                    graph1 = new ParagraphRenderData();
                    graph1.addText("纬度");
                    cell = new CellRenderData();
                    cell.addParagraph(graph1);
                    rowRenderData.addCell(cell);
                    int size = v.size()+3;
                    for(int i=3;i<size;i++){
                        ParagraphRenderData newPara = new ParagraphRenderData();
                        newPara.addText(imValues.get(i-3));
                        xxList.add(imValues.get(i-3));
                        CellRenderData newCell = new CellRenderData();
                        newCell.addParagraph(newPara);
                        rowRenderData.addCell(newCell);
                    }
                    tableRenderData.addRow(rowRenderData);
                }
                RowRenderData rowRenderData = new RowRenderData();
                ParagraphRenderData graph1 = new ParagraphRenderData();
                graph1.addText(v.get(0).getId());
                CellRenderData cell = new CellRenderData();
                cell.addParagraph(graph1);
                rowRenderData.addCell(cell);
                graph1 = new ParagraphRenderData();
                graph1.addText(v.get(0).getLongitude());
                cell = new CellRenderData();
                cell.addParagraph(graph1);
                rowRenderData.addCell(cell);
                graph1 = new ParagraphRenderData();
                graph1.addText(v.get(0).getLatitude());
                cell = new CellRenderData();
                cell.addParagraph(graph1);
                rowRenderData.addCell(cell);
                List<BigDecimal> fvalues = v.stream().map(ReportAnalysis::getFImValue).collect(Collectors.toList());
                for (int i = 0; i < fvalues.size(); i++) {
                    ParagraphRenderData newPara = new ParagraphRenderData();
                    BigDecimal fvalue = fvalues.get(i);
                    if("4".equals(inputMode)){
                        //超越概率危险性
                        if(i==fvalues.size()-1){
                            BigDecimal prefix = fvalues.get(i-1);
                            BigDecimal newValue = fvalue.multiply(fvalue).subtract(prefix);
                            fvalue = newValue;
                        }else{
                            BigDecimal post = fvalues.get(i+1);
                            BigDecimal newValue = (fvalue.subtract(post)).divide((BigDecimal.ONE.subtract(post)),2,BigDecimal.ROUND_HALF_DOWN);
                            fvalue = newValue;
                        }
                    }
                    newPara.addText(fvalue+"");
                    CellRenderData newCell = new CellRenderData();
                    newCell.addParagraph(newPara);
                    rowRenderData.addCell(newCell);
                    countList.add(fvalue);
                }
                map.put(v.get(0).getKilometerGridId(),countList);
                tableRenderData.addRow(rowRenderData);
//                MergeCellRule rule = MergeCellRule.builder().
//                        map(MergeCellRule.Grid.of(0, 0), MergeCellRule.Grid.of(1, 0)).
//                        map(MergeCellRule.Grid.of(0, 1), MergeCellRule.Grid.of(1, 1)).
//                        map(MergeCellRule.Grid.of(0, 2), MergeCellRule.Grid.of(1, 2)).
//                        map(MergeCellRule.Grid.of(1, 2), MergeCellRule.Grid.of(1, 12))
//                        .build();//
//
//                tableRenderData.setMergeRule(rule);
                paramMap.put("table",tableRenderData);
            }
            //折线图生成
            ChartMultiSeriesRenderData line = new ChartMultiSeriesRenderData();
            line.setChartTitle("易损性曲线");
            //参数为数组
            line.setChartTitle("地震危险性折线图");
            line.setCategories(xxList.toArray(new String[xxList.size()]));
            List<SeriesRenderData> seriesRenderDatas1 = new ArrayList<SeriesRenderData>();
            if(map.values().size()>0){
                map.forEach((k,v)->{
                    seriesRenderDatas1.add(new SeriesRenderData(k, v.toArray(new BigDecimal[v.size()])));
                });
            }
            line.setSeriesDatas(seriesRenderDatas1);
            paramMap.put("analyiseChart", line);
        }else{
            TableRenderData tableRenderData = new TableRenderData();
            RowRenderData rowRenderData = new RowRenderData();
            ParagraphRenderData graph1 = new ParagraphRenderData();
            graph1.addText("没有数据");
            CellRenderData cell = new CellRenderData();
            cell.addParagraph(graph1);
            rowRenderData.addCell(cell);
            tableRenderData.addRow(rowRenderData);
            paramMap.put("table",tableRenderData);
            ChartMultiSeriesRenderData line = new ChartMultiSeriesRenderData();
            line.setChartTitle("易损性曲线");
            //参数为数组
            line.setChartTitle("地震危险性折线图");
            List<BigDecimal> xxList = new ArrayList<>();
            String[] strings = new String[5];
            for(int i=0;i<5;i++){
                strings[i] = (0+"");
                xxList.add(BigDecimal.valueOf(0));
            }
            line.setCategories(strings);
            List<SeriesRenderData> seriesRenderDatas1 = new ArrayList<SeriesRenderData>();
            for (BigDecimal s : xxList) {
                seriesRenderDatas1.add(new SeriesRenderData(s+"", xxList.toArray(new BigDecimal[xxList.size()])));
            }
            line.setSeriesDatas(seriesRenderDatas1);
            paramMap.put("analyiseChart", line);
        }
    }

    private List<ReportAnalysis> getReportAnalysis(String type,String role, String userLevelrole) {
//        String sql = "select t.id,t.kilometer_grid_id,t.longitude,t.latitude,t1.im_value,t1.f_im_value from fxqh_ps_hazard_data_value t1 ,(select a.* from fxqh_ps_hazard_data a,district_boundary_county b where b.code='"+countyCode+"' and st_intersects ( ST_GeometryFromText(A.geom,4490), b.geom  )  limit 200) t where t.id = t1.ph_id  and t1.type = '"+type+"'";
//        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReportAnalysis.class));
        //role 0国家级管理员  1省级管理员  2市级管理员  3县级管理员   根据role决定查哪些表
        //userLevelrole 省级存省id,市级存市id,县级存县id,国家级存1  根据level决定查指定表中哪些数据
        String userID = PlatformSessionContext.getUserID();
        String sUser = sUserService.getSUser(userID);
        SUser user = CreateGson.createGson().fromJson(sUser, SUser.class);
        String areaId = "";
        if(PlatformObjectUtils.isNotEmpty(user.getProvinceId())){
            areaId+=(user.getProvinceId()+",");
        }
        if(PlatformObjectUtils.isNotEmpty(user.getCityId())){
            areaId+=(user.getCityId()+",");
        }
        if(PlatformObjectUtils.isNotEmpty(user.getCountyId())){
            areaId+=(user.getCountyId()+",");
        }
        if(areaId.endsWith(",")){
            areaId = areaId.substring(0,areaId.length()-1);
        }
        String areaName = sysAreaService.getAreaNameByAreaId(areaId);
        String sql = "";
        if("0".equals(role)){
            sql = "SELECT T.ID,T.kilometer_grid_id,T.longitude,T.latitude,t1.im_value,t1.f_im_value FROM" +
                    " fxqh_ps_hazard_data_value_country t1,(SELECT A.* FROM fxqh_ps_hazard_data_country A LIMIT 200 ) T WHERE" +
                    " T.ID = t1.ph_id AND t1.TYPE = '"+type+"' ";
        }else if("1".equals(role)){
            String province = "";
            if(areaName.split(",").length>1){
                province = areaName.split(",")[0];
            }
            sql = "SELECT T.ID,T.kilometer_grid_id,T.longitude,T.latitude,t1.im_value,t1.f_im_value FROM " +
                    "                   fxqh_ps_hazard_data_value_province t1,(SELECT A.* FROM fxqh_ps_hazard_data_province A where a.province='"+province+"' LIMIT 200 ) T WHERE T.ID = t1.ph_id AND t1.TYPE = '"+type+"' ";
        }else if("2".equals(role)){
            String province = "";
            String city = "";
            if(areaName.split(",").length>=1){
                province = areaName.split(",")[0];
            }
            if(areaName.split(",").length>=2){
                city = areaName.split(",")[1];
            }
            sql = "SELECT T.ID,T.kilometer_grid_id,T.longitude,T.latitude,t1.im_value,t1.f_im_value FROM\n" +
                    "                   fxqh_ps_hazard_data_value_city t1,(SELECT A.* FROM fxqh_ps_hazard_data_city A where A.province='"+province+"' and A.city='"+city+"' LIMIT 200 ) T WHERE T.ID = t1.ph_id AND t1.TYPE = '0' ";
        }else if("3".equals(role)){
            String province = "";
            String city = "";
            String county = "";
            if(areaName.split(",").length>=1){
                province = areaName.split(",")[0];
            }
            if(areaName.split(",").length>=2){
                city = areaName.split(",")[1];
            }
            if(areaName.split(",").length==3){
                county = areaName.split(",")[2];
            }
            sql = "SELECT T.ID,T.kilometer_grid_id,T.longitude,T.latitude,t1.im_value,t1.f_im_value FROM\n" +
                    "                   fxqh_ps_hazard_data_value_county t1,(SELECT A.* FROM fxqh_ps_hazard_data_county A where A.province='"+province+"' and A.city='"+city+"' and A.county='"+county+"' LIMIT 200 ) T WHERE T.ID = t1.ph_id AND t1.TYPE = '0' ";
        }
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReportAnalysis.class));
    }

    public List<PopulationAndLoss> getzhjgResult(QueryParam param){

        StringBuilder sql = new StringBuilder("select * from fxqh_composite_assess where task_id = '" + param.getId() + "' and category = '" + param.getCategory() + "'");
//        if (PlatformObjectUtils.isNotEmpty(param.getType())){
//            sql.append(" and type = '" + param.getType() + "'");
//        }
        List<PopulationAndLoss> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(PopulationAndLoss.class));
        return list;
    }
    public Map<String,Object> getcountryBytaskId(String taskId){
        StringBuilder sb = new StringBuilder();
        sb.append("SELECT * from fxqh_assess_toponym where assess_id=?");
        String sql = sb.toString();
        logger.info("getBuildingJzwysxDataList方法查询的SQL:{},参数:{}",sb.toString(),taskId);
        List<Map<String,Object>> dataList = jdbcTemplate.queryForList(sql,taskId);
        return dataList.get(0);
    }

    public List<Map<String,Object>> selectByTypeList(String type1,String type2,String type3){
        StringBuilder sb = new StringBuilder();
        sb.append("select type,'<='||cast(v1 as FLOAT)/100 as v1,'('||cast(v1 as FLOAT)/100||','||cast(v2 as FLOAT)/100||']' as v2,'('||cast(v2 as FLOAT)/100||','||cast(v3 as FLOAT)/100||']' as v3,'('||cast(v3 as FLOAT)/100||','||cast(v4 as FLOAT)/100||']' as v4,'>='||cast(v4 as FLOAT)/100 as v5 \n" +
                "from fxqh_single_indicator_risk_zone_set where type in ('"+type1+"','"+type2+"','"+type3+"') order by type");
        String sql = sb.toString();
        logger.info("selectByTypeList方法查询的SQL:{},参数:{}",sb.toString());
        List<Map<String,Object>> dataList = jdbcTemplate.queryForList(sql);
        return dataList;
    }

    public List<Map<String,Object>> selectzhByTypeList(String type1,String type2,String type3){
        StringBuilder sb = new StringBuilder();
        sb.append("select type,'<='||cast(v1 as FLOAT)/100 as v1,'('||cast(v1 as FLOAT)/100||','||cast(v2 as FLOAT)/100||']' as v2,'('||cast(v2 as FLOAT)/100||','||cast(v3 as FLOAT)/100||']' as v3,'('||cast(v3 as FLOAT)/100||','||cast(v4 as FLOAT)/100||']' as v4,'>='||cast(v4 as FLOAT)/100 as v5 \n" +
                "from fxqh_comprehensive_risk_zone_set where type in ('"+type1+"','"+type2+"','"+type3+"') order by type");
        String sql = sb.toString();
        logger.info("selectzhByTypeList方法查询的SQL:{},参数:{}",sb.toString());
        List<Map<String,Object>> dataList = jdbcTemplate.queryForList(sql);
        return dataList;
    }

    private List<ReportYsxVO> getReportYsxDataList(String taskId){
        final String sql = "select a.province,a.city,a.county,concat(structure_type1,structure_type2) structure,a.fortify,b.intensity,b.damage,b.rate from fxqh_jzwysx_copy a,fxqh_jzwysx_sub_copy b where a.id=b.pid and a.task_id='"+taskId+"'";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(ReportYsxVO.class));
    }

    private List<Map<String,Object>> buildReportYsxData(List<ReportYsxVO> ysxList){
        List<Map<String,Object>> resultList = new ArrayList<>();
        Map<String,List<ReportYsxVO>> map = new HashMap<>();
        String county = "";
        if(PlatformObjectUtils.isNotEmpty(ysxList) && ysxList.size()>0){
            for (ReportYsxVO reportYsxVO : ysxList) {
                if(org.apache.commons.lang3.StringUtils.isBlank(county)){
                    county = reportYsxVO.getCounty();
                }
                if(county.equals(reportYsxVO.getCounty())){
                    if(!map.containsKey(reportYsxVO.getProvince()+"-"+reportYsxVO.getCity()+"-"+reportYsxVO.getCounty()+"-"+reportYsxVO.getStructure())){
                        List<ReportYsxVO> list = new ArrayList<>();
                        list.add(reportYsxVO);
                        map.put(reportYsxVO.getProvince()+"-"+reportYsxVO.getCity()+"-"+reportYsxVO.getCounty()+"-"+reportYsxVO.getStructure(),list);
                    }else{
                        List<ReportYsxVO> list = map.get(reportYsxVO.getProvince() + "-" + reportYsxVO.getCity() + "-" + reportYsxVO.getCounty() + "-" + reportYsxVO.getStructure() );
                        list.add(reportYsxVO);
                        map.put(reportYsxVO.getProvince()+"-"+reportYsxVO.getCity()+"-"+reportYsxVO.getCounty()+"-"+reportYsxVO.getStructure(),list);
                    }
                }
            }
            if(map.values().size()>0){
                map.forEach((k,v)->{
                    Map<String,List<ReportYsxVO>> forityMap = new HashMap();
                    for (ReportYsxVO reportYsxVO : v) {
                        if(!forityMap.containsKey(reportYsxVO.getFortify())){
                            List<ReportYsxVO> list = new ArrayList<>();
                            list.add(reportYsxVO);
                            forityMap.put(reportYsxVO.getFortify(),list);
                        }else{
                            List<ReportYsxVO> list = forityMap.get(reportYsxVO.getFortify() );
                            list.add(reportYsxVO);
                            forityMap.put(reportYsxVO.getFortify(),list);
                        }
                    }
                    Map<String, List<ReportYsxVO>> result = new LinkedHashMap<>();
                    forityMap.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(x -> result.put(x.getKey(), x.getValue()));
                    if(result.values().size()>0){
                        result.forEach((k1,v1)->{
                            Map<String,List<ReportYsxVO>> damageMap = new HashMap();
                            for (ReportYsxVO reportYsxVO : v1) {
                                if(!damageMap.containsKey(reportYsxVO.getDamage())){
                                    List<ReportYsxVO> list = new ArrayList<>();
                                    list.add(reportYsxVO);
                                    damageMap.put(reportYsxVO.getDamage(),list);
                                }else{
                                    List<ReportYsxVO> list = damageMap.get(reportYsxVO.getDamage() );
                                    list.add(reportYsxVO);
                                    damageMap.put(reportYsxVO.getDamage(),list);
                                }
                            }
                            if(damageMap.values().size()>0){
                                List<String> damageList = getDamageList();
                                for (String damage : damageList) {
                                    List<ReportYsxVO> reportYsxVOS = damageMap.get(damage);
                                    if(PlatformObjectUtils.isNotEmpty(reportYsxVOS) && reportYsxVOS.size()>0){
                                        //ReportYsx ysx = new ReportYsx();
                                        Map<String,Object> resultMap = new HashMap<>();
                                        resultMap.put("province",reportYsxVOS.get(0).getProvince());
                                        resultMap.put("city",reportYsxVOS.get(0).getCity());
                                        resultMap.put("county",reportYsxVOS.get(0).getCounty());
                                        resultMap.put("structure_type",reportYsxVOS.get(0).getStructure());
                                        resultMap.put("fortify",reportYsxVOS.get(0).getFortify());
                                        resultMap.put("damage",reportYsxVOS.get(0).getDamage());
                                        resultMap.put("province",reportYsxVOS.get(0).getProvince());
                                        String rate6 = "0.00";
                                        String rate7 = "0.00";
                                        String rate8 = "0.00";
                                        String rate9 = "0.00";
                                        String rate10 = "0.00";
                                        for(int i=0;i<reportYsxVOS.size();i++){
                                            if(PlatformObjectUtils.isNotEmpty(reportYsxVOS.get(i).getRate())){
                                                if("6度".equals(reportYsxVOS.get(i).getIntensity())){
                                                    rate6 = reportYsxVOS.get(i).getRate().replace("%","");
                                                }else if("7度".equals(reportYsxVOS.get(i).getIntensity())){
                                                    rate7 = reportYsxVOS.get(i).getRate().replace("%","");
                                                }else if("8度".equals(reportYsxVOS.get(i).getIntensity())){
                                                    rate8 = reportYsxVOS.get(i).getRate().replace("%","");
                                                }else if("9度".equals(reportYsxVOS.get(i).getIntensity())){
                                                    rate9 = reportYsxVOS.get(i).getRate().replace("%","");
                                                }else if("10度".equals(reportYsxVOS.get(i).getIntensity())){
                                                    rate10 = reportYsxVOS.get(i).getRate().replace("%","");
                                                }
                                            }
                                        }
                                        resultMap.put("rate_6",rate6);
                                        resultMap.put("rate_7",rate7);
                                        resultMap.put("rate_8",rate8);
                                        resultMap.put("rate_9",rate9);
                                        resultMap.put("rate_10",rate10);
                                        resultList.add(resultMap);
                                    }
                                }
                            }
                        });
                    }
                });
            }
        }
        return resultList;
    }
    private List<String> getDamageList(){
        return Arrays.asList("基本完好","轻微破坏","中等破坏","严重破坏","倒塌");
    }
    @Override
    public List<Map<String,Object>> getBuildingJzwysxDataList(String taskId){
        StringBuilder sb = new StringBuilder();
        sb.append("select                                                                                                                                       ");
        sb.append("	A.province,                                                                                                                          ");
        sb.append("	A.city,                                                                                                                              ");
        sb.append("	A.county,                                                                                                                            ");
        sb.append("	A.fortify,                                                                                                                           ");
        sb.append("	concat ( A.structure_type1, A.structure_type2 ) AS structure_type,                                                                   ");
        sb.append("	b.damage,                                                                                                                            ");
        sb.append("	b.rate_6,                                                                                                                            ");
        sb.append("	b.rate_7,                                                                                                                            ");
        sb.append("	b.rate_8,                                                                                                                            ");
        sb.append("	b.rate_9,                                                                                                                            ");
        sb.append("	b.rate_10                                                                                                                            ");
        sb.append("                                                                                                                                             ");
        sb.append("from fxqh_jzwysx_copy                                                                                                                        ");
        sb.append("	A INNER JOIN                                                                                                                         ");
        sb.append("                                                                                                                                             ");
        sb.append("(                                                                                                                                            ");
        sb.append("		SELECT                                                                                                                       ");
        sb.append("				pid,                                                                                                         ");
        sb.append("				damage,                                                                                                      ");
        sb.append("				sum(CASE WHEN intensity = '6度' THEN rate  ELSE 0 END) AS rate_6,                                            ");
        sb.append("				sum(CASE WHEN intensity = '7度' THEN rate ELSE 0 END) AS rate_7,                                             ");
        sb.append("				sum(CASE WHEN intensity = '8度' THEN rate ELSE 0 END) AS rate_8,                                             ");
        sb.append("				sum(CASE WHEN intensity = '9度' THEN rate ELSE 0 END) AS rate_9,                                             ");
        sb.append("				sum(CASE WHEN intensity = '10度' THEN rate ELSE 0 END) AS rate_10                                            ");
        sb.append("		FROM (                                                                                                                       ");
        sb.append("			SELECT t.pid, t.intensity,t.damage,cast(replace(t.rate,'%','') as DEC(10,2)) as rate  FROM fxqh_jzwysx_sub_copy t    ");
        sb.append("		) t                                                                                                                          ");
        sb.append("		group BY pid,damage                                                                                                          ");
        sb.append("		                                                                                                                             ");
        sb.append(") b  ON A.ID = b.pid                                                                                                                         ");
        sb.append(" left join ( SELECT * FROM sys_dict_item where dict_id ='100001') c on c.dict_item_name=a.fortify ");
        sb.append("where                                                                                                       ");
        //sb.append(" a.task_id='%s'                                                                                                                         ");
        sb.append(" a.task_id=?                                                                                                                 ");
        sb.append("  ORDER BY c.sort, ");
        sb.append(" (damage='基本完好',damage='轻微破坏',damage='中等破坏',damage='严重破坏',damage='倒塌',damage='破坏' or damage='倒塌') DESC                 ");
        String sql = sb.toString();
        logger.info("getBuildingJzwysxDataList方法查询的SQL:{},参数:{}",sb.toString(),taskId);
        List<Map<String,Object>> dataList = jdbcTemplate.queryForList(sql,taskId);
        return dataList;
    }

    private AttachmentInfoEntity buildAttachment(String fileName, String dateDir,String realFileName) {

        AttachmentInfoEntity attachmentInfoEntity = new AttachmentInfoEntity();
        attachmentInfoEntity.setAttachId(StringUtils.buildPrimaryId());
        attachmentInfoEntity.setAttachName(fileName);
        attachmentInfoEntity.setAttachPath( dateDir + "/" + realFileName);
        attachmentInfoEntity.setFileDirId(localDir);
        attachmentInfoEntity.setIsValid("1");
        attachmentInfoEntity.setIsCompleted("1");
        return attachmentInfoEntity;
    }


    /**
     * 生产word报告
     * @param policyMap
     * @param paramMap
     * @param inputNum   模板编号
     *  地震输入方式
     * 1000000101：建筑物-确定评估设定烈度
     * 1000000102：建筑物-确定评估四个概率水准
     * 1000000103：建筑物-确定评估设定地震影响场
     * 1000000301：生命线工程评估设定烈度
     * 1000000302：生命线工程评估设定地震影响场
     * 1000000201：建筑物-概率评估发生概率
     * @return
     */
    public  Map<String, String> createWordReport1(Map<String,RenderPolicy> policyMap, Map<String, Object> paramMap,String inputNum,String bgId) throws Exception {
        // 文件存放根目录
        //deskDocxPath  具体生成目标路径地址 包含后缀
        Template byTemplateName = templateRepository.getByTemplateInput(inputNum);
        AttachmentInfoEntity attach = attachmentInfoService.getAttach(byTemplateName.getAttachId());
        String srcDocxPath ="";//srcDocxPath  模板具体地址 包含后缀
        String fileName=attach.getAttachName();
        if(PlatformObjectUtils.isNotEmpty(attach)){
            //获取文件的路径
           //srcDocxPath = "D:\\static\\2023\\11\\27\\04概率评估-发生概率_1701066526652.docx";
            //srcDocxPath = "D:\\static\\2024\\03确定评估-设定地震影响场.docx";
            //srcDocxPath = "D:\\static\\2024\\04概率评估-发生概率.docx";
            //srcDocxPath = "D:\\static\\2024\\1.docx";
           //srcDocxPath = "D:\\static\\2024\\02确定评估-四个概率水准.docx";
            //srcDocxPath = "D:\\static\\2024\\01确定评估-设定烈度.docx";
            srcDocxPath= attach.getFileDirId()+ File.separator+attach.getAttachPath();
        }
        //获取文件上传的本地路径
        String dateDir = new SimpleDateFormat("/yyyy/MM/dd").format(new Date());
        String savePath = localDir + dateDir;
        //判断文件夹是否存在如果不存在则创建
        if(!new File(savePath).exists()){
            new File(savePath).mkdirs();
        }
        // 获取文件的后缀名
        assert fileName != null;
        String preFileName = fileName.substring(0,fileName.lastIndexOf("."));
        // .jpg  .pdf  .txt  .docs
        String fileType = fileName.substring(fileName.lastIndexOf("."));
        // 拼文件名  真实的文件名称
        String realFileName = preFileName + "_"  + System.currentTimeMillis() + fileType;

        String deskDocxPath=savePath+ File.separator+realFileName;
        try (
                InputStream inputStream = new FileInputStream(srcDocxPath)) {
            ConfigureBuilder builder = Configure.builder()
                    .useSpringEL()  //使用SpringEL表达式
                    .buildGrammerRegex(RegexUtils.createGeneral("{{", "}}"));//允许除了标签前后缀外的任意字符

            Set<String> listKeySet = policyMap.keySet();
            for (String key:listKeySet) {
                builder= builder.bind(key,policyMap.get(key));
            }
            Configure config = builder.build();
            // 通过协查函模板，开始生成电子协查函
            try (
                    XWPFTemplate template = XWPFTemplate.compile(inputStream,config).render(paramMap);
                    OutputStream outDocx = Files.newOutputStream(Paths.get(deskDocxPath))) {

                ZipSecureFile.setMinInflateRatio(-1D);
                // 输出word
                template.getXWPFDocument().write(outDocx);
            }catch (Exception e){
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        //构建实体类
        List<AttachmentInfoEntity> attachmentInfoEntities = new ArrayList<>();
        AttachmentInfoEntity attachmentInfoEntity = buildAttachment(fileName,dateDir,realFileName);
        attachmentInfoEntities.add(attachmentInfoEntity);
        attachmentInfoService.save(attachmentInfoEntities);
        String user = sUserService.getSUser(PlatformSessionContext.getUserID());
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        this.updateBybgId(attachmentInfoEntity.getAttachId(),attachmentInfoEntity.getAttachName(),bgId,sUser);
        Map<String, String> map = new HashMap<>(4);
        map.put("fileId",attachmentInfoEntity.getAttachId());
        return map;
    }


    public void updateBybgId(String fileId,String fileName,String bgId,SUser sUser){
        String sql = "update fxqh_calculation_tasks_report set report_file_id = '" + fileId + "', report_file_name = '" + fileName + "',create_time=now(),create_user='"+sUser.getUserName()+"',create_user_id='"+sUser.getUserId()+"'  where id = '" + bgId + "'";
        jdbcTemplate.update(sql);
    }


    public static void main(String[] args) {
        System.out.println(UUIDGenerator.getUUID());
        System.out.println(UUIDGenerator.getUUID());
        System.out.println(UUIDGenerator.getUUID());
        System.out.println(UUIDGenerator.getUUID());
        System.out.println(UUIDGenerator.getUUID());
        System.out.println(UUIDGenerator.getUUID());
    }

    public void commonTable(String[] yearSplit,Map<String, Object> paramMap,List<Map<String,Object>> listMap,String key) throws Exception{

        List<String> titlesCommon=new LinkedList<>();
        titlesCommon.add("省");
        titlesCommon.add("市");
        titlesCommon.add("县");
        if(!"economicLossMethodList".equals(key)){
            titlesCommon.add("白天/夜间");
        }
       // String[] yearSplit="1,5,30".split(",");
        List<String> years = Arrays.asList(yearSplit);

        List<String> titles0=new LinkedList<>(titlesCommon);
        if("dzzhDzryqkTableList1".equals(key)){
            titles0.add("人员受伤期望（人）1");
        }else if("dzzhDzryqkTableList2".equals(key)){
            titles0.add("人员死亡期望（人）");
        }else if("economicLossMethodList".equals(key)){
            titles0.add("经济损失期望（万元）");
        }
        //titles0.add("人员受伤期望（人）");
        titles0.addAll(Collections.nCopies(years.size() - 1, null));

        List<String> titles2=new LinkedList<>(titlesCommon);
        titles2.addAll(years);

        // 第0行居中且背景为蓝色的表格
//        List<Map<String,Object>> listMap=new ArrayList<>();
//        Map<String,Object> map11=new LinkedHashMap<>();
//        map11.put("s1","1");
//        map11.put("s2","2");
//        map11.put("s3","3");
//        map11.put("s4","4");
//        map11.put("s5","8");
//        map11.put("s6","6");
//        map11.put("s7","7");
//        listMap.add(map11);

        // 假设list中的每个Map都有一个名为"values"的键，其值为List<String>
        List<List<String>> result = IntStream.range(0, listMap.size())
                .mapToObj(i -> new ArrayList<>(listMap.get(i).values().stream()
                        .map(Object::toString)
                        .collect(Collectors.toList())))
                .collect(Collectors.toList());
        System.out.println(result);
        int length = listMap.size();
        RowRenderData[] rowRenderData = new RowRenderData[length + 2];
        for (int i = 0; i < length; i++) {
            rowRenderData[i + 2] = Rows.of(result.get(i).toArray(new String[0])).center().create();
        }
        RowRenderData row0 = Rows.of(titles0.toArray(new String[0])).center().create();
        RowRenderData row1 = Rows.of(titles2.toArray(new String[0])).center().create();
        rowRenderData[0] = row0;
        rowRenderData[1] = row1;
        if("economicLossMethodList".equals(key)){
            MergeCellRule rule = MergeCellRule.builder().
                    map(MergeCellRule.Grid.of(0, 0), MergeCellRule.Grid.of(1, 0)).
                    map(MergeCellRule.Grid.of(0, 1), MergeCellRule.Grid.of(1, 1)).
                    map(MergeCellRule.Grid.of(0, 2), MergeCellRule.Grid.of(1, 2)).build();
                    //map(MergeCellRule.Grid.of(0, 3), MergeCellRule.Grid.of(0, titles0.size()-1))/合并表头
            paramMap.put(key, Tables.of(rowRenderData).mergeRule(rule).create());
        }else {
            MergeCellRule rule = MergeCellRule.builder().
                    map(MergeCellRule.Grid.of(0, 0), MergeCellRule.Grid.of(1, 0)).
                    map(MergeCellRule.Grid.of(0, 1), MergeCellRule.Grid.of(1, 1)).
                    map(MergeCellRule.Grid.of(0, 2), MergeCellRule.Grid.of(1, 2)).
                    map(MergeCellRule.Grid.of(0, 3), MergeCellRule.Grid.of(1, 3)).build();
                    //map(MergeCellRule.Grid.of(0, 4), MergeCellRule.Grid.of(0, titles0.size()-1));//合并表头
            paramMap.put(key, Tables.of(rowRenderData).mergeRule(rule).create());
        }

    }

}
